Bug 277333 - Example of using custom query keys for casting of relationships into inheritance hierarchy
Summary: Example of using custom query keys for casting of relationships into inherita...
Status: CLOSED WONTFIX
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL: http://wiki.eclipse.org/EclipseLink/J...
Whiteboard: under development and review
Keywords: example
Depends on:
Blocks:
 
Reported: 2009-05-21 10:35 EDT by Doug Clarke CLA
Modified: 2022-06-09 10:29 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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