omnifaces / optimusfaces

Utility library for OmniFaces + PrimeFaces combined

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Double Colon Notation (Object Graph Navigation)

mydeadlyvenoms opened this issue · comments

After reading the JavaDoc it is clear there are different ways to perform access control checks on a record level. One can use a filter within the frontend or the backend. I stuck if I would like to filter records using a Criteria in the frontend and the User Object (I would like to compare) is not directly accessible (via a Getter) of the entity.

In other words, I need to use the double colon notation multiple times to navigate trough the object graph to reach the related user object of a given entity.

I tried to add a simple additional Getter to my model like the following:

public User getUser() {
    return x.getY().getZ().getUser();
}

But this produces an IllegalArgumentException (java.lang.IllegalArgumentException: The attribute [user] is not present in the managed type ...)

Makes sense.

This is reliably to detect if it's @OneToOne at all levels, but not really for @ManyToOne.

Try today's 0.6-SNAPSHOT and let me know.

I just tried the latest SNAPSHOT.
The exception is gone but no results are shown, I guess something is wrong when having this criteria.
The filter on record level should work fine since it works fine when having the user field directly accessible without an additional getter (pattern from above).

I'll try to further investigate the behavior.

Hi @BalusC
I can confirm, the implemented solution works!
Thank you very much for your help.

Great. Thank you for the feedback.

Hi @BalusC
I tried another couple of things today using OptimusFaces and I found out that the fix doesn't work anymore if the model makes use of entity inheritance. I'll try to further investigate and keep you posted. Maybe you already have an idea - might be that I am completely on the wrong track. :-)
Current situation is that the resulting op:dataTable is always empty when querying the sub-entity.

Model

@Entity
public class A extends TimestampedEntity<Long> {

   ...

    public User getUser() {
        return x.getY().getZ().getUser();
    }

}
@Entity
public class B extends A {

...

}

I just did a few more tests and it really seems so depend on the entity inheritance (via extends, mappedsuperclass seems to work fine).
Do you have any pointers where I can find the responsible pieces of code (within OmniPersistence)?
Maybe it has something todo with reflection(s)?
BTW: Can you please open the issue again - maybe others have similar problems. Or let me know if I better create a new one.

Thank you for your response. Okay I see. The strange thing is there is no direct Many/OneToOne mapping even within the "parent" entity - this is the reason why I created the additional getUser method (which works fine when using it as criteria in the backing bean). The only problem is that the inheriting entity cannot make use of it (the resulting dataTable is always empty).