|
Re: Join on concatenated columns [message #760231 is a reply to message #759871] |
Thu, 01 December 2011 16:24 |
Chris Delahunt Messages: 1389 Registered: July 2009 |
Senior Member |
|
|
Hello,
From what you are asking, it looks like A.FILE || '.' || A.NUMBER is the foreign key to B.ID, which means you have the mappings backwards. A would have a OneToOne to B, not the other way around. I assume that you would also have basic mappings for A.FILE and A.NUMBER.
Unfortunately what you are after is not possible in pure JPA - I am surprised you are not getting an exception or warning from Eclipselink elsewhere, as it should expect the "FILE || '.' || NUMBER" as a single field within the A table ie: "A.FILE || '.' || NUMBER".
It might be possible in EclipseLink to modify the mapping's selection criteria using customizers and make it read only. But I would recommend you not map the A<->B relationships and instead use a query when you want to access the associations:
"Select a, b from A a, B b where concat(a.file, concat('.', a.number)) = :bid"
which will return all A objects with its B object or
"Select a from A a where concat(a.file, concat('.', a.number)) = :bid"
and pass in the bid as a parameter for a particular B's As.
If you decide to go the mapping modification route, see http://wiki.eclipse.org/EclipseLink/Examples/JPA/MappingSelectionCriteria
for information on setting selection criteria on a mapping, and http://wiki.eclipse.org/Introduction_to_EclipseLink_Expressions_(ELUG)
on building the expressions needed by the mapping.
Best Regards,
Chris
|
|
|
Re: Join on concatenated columns [message #760233 is a reply to message #759871] |
Thu, 01 December 2011 16:24 |
Chris Delahunt Messages: 1389 Registered: July 2009 |
Senior Member |
|
|
Hello,
From what you are asking, it looks like A.FILE || '.' || A.NUMBER is the foreign key to B.ID, which means you have the mappings backwards. A would have a OneToOne to B, not the other way around. I assume that you would also have basic mappings for A.FILE and A.NUMBER.
Unfortunately what you are after is not possible in pure JPA - I am surprised you are not getting an exception or warning from Eclipselink elsewhere, as it should expect the "FILE || '.' || NUMBER" as a single field within the A table ie: "A.FILE || '.' || NUMBER".
It might be possible in EclipseLink to modify the mapping's selection criteria using customizers and make it read only. But I would recommend you not map the A<->B relationships and instead use a query when you want to access the associations:
"Select a, b from A a, B b where concat(a.file, concat('.', a.number)) = :bid"
which will return all A objects with its B object or
"Select a from A a where concat(a.file, concat('.', a.number)) = :bid"
and pass in the bid as a parameter for a particular B's As.
If you decide to go the mapping modification route, see http://wiki.eclipse.org/EclipseLink/Examples/JPA/MappingSelectionCriteria
for information on setting selection criteria on a mapping, and http://wiki.eclipse.org/Introduction_to_EclipseLink_Expressions_(ELUG)
on building the expressions needed by the mapping.
Best Regards,
Chris
|
|
|
Powered by
FUDForum. Page generated in 0.03032 seconds