Query across Variable One to One mapping [message #537838] |
Thu, 03 June 2010 15:41  |
Eclipse User |
|
|
|
Hi, lets say I have an interface I, and I have two implementors of that interface A and B. Now lets say I have established a Variable one to one relationship from a class X to I via the EclipseLink VariableOneToOne JPA extension annotation.
How can I write a JPQL query that will find me all instances of X via an EntityManager, where those instances of X reference an I implementor that is in a given state? For example, I wish to find all instances of X where the instance references an instance of A or B, such that an int property of A or B (expressed as an operation on I?) has a given value such as 5.
Thank you,
Doug
|
|
|
Re: Query across Variable One to One mapping [message #538463 is a reply to message #537838] |
Mon, 07 June 2010 12:47  |
Eclipse User |
|
|
|
Joins are not supported across VariableOneToOne relationships, so this is not easy to do. Since there are two or more different tables/entities you will need to query or join multiple tables.
One option is to define a OneToOneQueryKey to both of the implementers of the Interface and in your query join both of the query keys. Note that query key support to JPQL was added in EclipseLink 2.1, previously you would need to use an Expression (or Criteria) query to access query keys.
Another option is to use a native SQL query, or switch the mapping to two different OneToOne mappings.
Please log an enhancement request to have support for joining VariableOneToOne relationships and vote for it.
|
|
|
Powered by
FUDForum. Page generated in 0.03773 seconds