Summary: | Example of using custom query keys for casting of relationships into inheritance hierarchy | ||
---|---|---|---|
Product: | z_Archived | Reporter: | Doug Clarke <douglas.clarke> |
Component: | Eclipselink | Assignee: | Nobody - feel free to take it <nobody> |
Status: | CLOSED WONTFIX | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | CC: | fs5, matthias.bross |
Version: | unspecified | Keywords: | example |
Target Milestone: | --- | ||
Hardware: | All | ||
OS: | All | ||
URL: | http://wiki.eclipse.org/EclipseLink/JPA/CastingUsingQueryKey | ||
Whiteboard: | under development and review |
Description
Doug Clarke
2009-05-21 10:35:36 EDT
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 The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink |