Bug 277333

Summary: Example of using custom query keys for casting of relationships into inheritance hierarchy
Product: z_Archived Reporter: Doug Clarke <douglas.clarke>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: fs5, matthias.bross
Version: unspecifiedKeywords: example
Target Milestone: ---   
Hardware: All   
OS: All   
URL: http://wiki.eclipse.org/EclipseLink/JPA/CastingUsingQueryKey
Whiteboard: under development and review

Description Doug Clarke CLA 2009-05-21 10:35:36 EDT
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
Comment 1 Doug Clarke CLA 2009-05-21 11:55:51 EDT
Initial version of example checked in @ /svnroot/rt/org.eclipse.persistence/branches/1.1.0/trunk/examples/org.eclipse.persistence.example.jpa.cast
Comment 2 Doug Clarke CLA 2009-05-21 11:59:10 EDT
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();
Comment 3 Doug Clarke CLA 2010-06-06 08:56:28 EDT
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.
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:16:58 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:29:21 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink