Community
Participate
Working Groups
This example will use custom relationship query keys to show how queries can be built that reference into an inheritance hierarchy below the root and thus provide access to additional mapped values of the subclasses. This example is based on the User Guide's documentation on how to add custom query keys in Java code: http://wiki.eclipse.org/Configuring_a_Descriptor_(ELUG)#How_to_Configure_Query_Keys_Using_Java
Initial version of example checked in @ /svnroot/rt/org.eclipse.persistence/branches/1.1.0/trunk/examples/org.eclipse.persistence.example.jpa.cast
The interesting part of this example is the CastQueryKeyFactory that creates the custom query keys based on an existing mapping and a new target subclass. http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/branches/1.1.0/trunk/examples/org.eclipse.persistence.example.jpa.cast/src/utils/CastQueryKeyFactory.java In this example a custom query key is created called 'oneToOneA' and is then used in a simple query: CastQueryKeyFactory.addCastQueryKey(getEMF(), Source.class, "oneToOne", InhChildA.class, "oneToOneA"); EntityManager em = getEntityManager(); ReadAllQuery raq = new ReadAllQuery(Source.class); ExpressionBuilder eb = raq.getExpressionBuilder(); raq.setSelectionCriteria(eb.get("oneToOneA").get("aValue").like("a%")); raq.setShouldOuterJoinSubclasses(true); raq.addAscendingOrdering("id"); List<Source> sources = JpaHelper.createQuery(raq, em).getResultList();
Given the new support for both casting (TREAT AS) in JPQL as well as support for using query keys in JPQL I am going to change the wiki to indicate that the examples shown were for versions before 2.1. No additional work on this example will be performed.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink