Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] How to get the "mappedBy" attribute name of a relation Attribute in a OneToOneMapping

Hi Chris,
thank you very much, this works! I would be curious to know why other methods on DatabaseMapping don't work as I would expect (like isOwned()... seems to return false for both owned and non-owned relationships, or the already mentioned getRelationshipPartnerAttributeName() and getRelationshipPartner(), which always return null), anyway my problem is solved.

I would just add that I'm not yet convinced that the problem I described is not a 'bug'. IMHO (I'm not a spec expert though), the specification part you cited says:
"Path _expression_ navigability is composed using “inner join” semantics. That is, if the value of a non-terminal field in the path _expression_ is null, the path is considered to have no value, and does not participate in the determination of the result."

But in my case, when I'm expressing (through a Criteria API query) the following:
WHERE First.second IS NULL
I'm not navigating the relationship (like I would if I were writing something like First.second.foo IS NULL). Also, "second" is not a non-terminal field in the path _expression_, on the contrary it's exactly the terminal field! So I'm not convinced the use of an inner join here is justified by the above statement.
I'm still convinced that the actual result when using "WHERE First.second IS NULL" should not differ if the mapping says that First owns the relationship or if it says that Second owns it. It's incoherent. If you still think it's a specification problem, then I would appreciate if my report is forwarded to the specification guys.

Thanks again for your help!
Mauro

Il 08/01/2016 19:15, christopher delahunt ha scritto:
I got a bit muddled while editing the code.

Standard 1:1 relationship in JPA is a foreignKeyRelationship in EclipseLink, and a join is NOT required.
MappedBy relationship in JPA is a targetForeignKeyRelationship in EclipseLink, and a join IS required. 

DatabaseMapping mapping = ((SingularAttributeImpl) attribute).getMapping();
if (mapping.isOneToOneRelationship() && !((OneToOneMapping)mapping).isForeignKeyRelationship()) {
  cq.where(cb.isNull(root.join(First_second, JoinType.LEFT)));
} else {
  cq.where(cb.isNull(root.get(First_second)));
}


I haven't tested it, so it may need some work to compile.

Best Regards,
Chris


Back to the top