Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 320254

Summary: EL 2.1.0 JPA: Query with hint eclipselink.batch and org.eclipse.persistence.exceptions.QueryException.queryHintNavigatedNonExistantRelationship
Product: z_Archived Reporter: Michael Braeuer <michael.braeuer>
Component: EclipselinkAssignee: Tom Ware <tom.ware>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: corteggiano, eclipselink.orm-inbox, michael.braeuer, peter.krogh, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: submitted_patch
Attachments:
Description Flags
Tescase for reproducing problem.
none
proposed patch peter.krogh: iplog+

Description Michael Braeuer CLA 2010-07-19 09:04:45 EDT
Build Identifier: 2.1.0.v20100614-r7608

When using a batch hint navigating along a relationship in a JPQL Query an exception is thrown.

Application code:

...

EntityManagerFactory emf = Persistence
.createEntityManagerFactory("EL-05-ELPerformance");

EntityManager em = emf.createEntityManager();
		
List<PurchaseOrder> pos  = (List<PurchaseOrder>) em
		.createQuery(
		"SELECT po FROM PurchaseOrder po WHERE po.status = 'ACTIVE' AND po.customer.address.city = 'SFO'")
		.setHint("eclipselink.join-fetch", "po.customer")
		.setHint("eclipselink.join-fetch", "po.customer.address")
		.setHint("eclipselink.batch", "po.customer.phoneNumbers")
	    .getResultList();

...

Exception:
Exception in thread "main" Local Exception Stack: 
Exception [EclipseLink-6143] (Eclipse Persistence Services - 2.1.0.v20100614-r7608): org.eclipse.persistence.exceptions.QueryException
Exception Description: The value po.customer.phoneNumbers supplied to the query hint eclipselink.batch navigated a non-existant relationship.  The relationship customer.phoneNumbers does not exist.
Query: ReadAllQuery(referenceClass=PurchaseOrder sql="SELECT t0.ID, t0.STATUS, t0.CUST_ID FROM PO t0, CUST t2, ADDR t1 WHERE (((t0.STATUS = ?) AND (t1.CITY = ?)) AND ((t2.ID = t0.CUST_ID) AND (t1.ID = t2.ADDR_ID)))")
	at org.eclipse.persistence.exceptions.QueryException.queryHintNavigatedNonExistantRelationship(QueryException.java:1327)
	at org.eclipse.persistence.internal.jpa.QueryHintsHandler$BatchHint.applyToDatabaseQuery(QueryHintsHandler.java:1198)
	at org.eclipse.persistence.internal.jpa.QueryHintsHandler$Hint.apply(QueryHintsHandler.java:345)
	at org.eclipse.persistence.internal.jpa.QueryHintsHandler$Hint.apply(QueryHintsHandler.java:323)
	at org.eclipse.persistence.internal.jpa.QueryHintsHandler.apply(QueryHintsHandler.java:163)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setHintInternal(EJBQueryImpl.java:962)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setHint(EJBQueryImpl.java:944)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setHint(EJBQueryImpl.java:73)
	at tester.EntityTester.main(EntityTester.java:26) 

Relationship exists in metamodel and it works with build 2.0.2.v20100323-r6872.

Reproducible: Always

Steps to Reproduce:
1. use uploaded eclipse project. 
2. run EntityTester.java
Comment 1 Michael Braeuer CLA 2010-07-19 09:07:41 EDT
Created attachment 174613 [details]
Tescase for reproducing problem.

In order to create schema use DropAndCreate.sql in Oracle DB.
Adjust persistence.xml
Comment 2 corteggiano CLA 2010-07-22 12:07:19 EDT
I filed a similar bug (320446) with details of the faulty code at EclipseLink 2.1 source code.
Comment 3 Tom Ware CLA 2010-08-09 13:56:17 EDT
Setting target and priority.  See the following page for details of the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Comment 4 Frank Schwarz CLA 2010-09-16 17:40:50 EDT
Created attachment 179076 [details]
proposed patch

The patch just realizes what was indicated in Bug 320446 by corteggiano@gmail.com
Comment 5 Tom Ware CLA 2010-09-27 10:34:15 EDT
*** Bug 320446 has been marked as a duplicate of this bug. ***
Comment 6 Tom Ware CLA 2010-09-30 13:15:30 EDT
Checked in fix with an additional null check

Added test to EntityManagerJunitTestSuite

Tested with JPA LRG
Comment 7 Peter Krogh CLA 2010-12-06 15:51:00 EST
setting iplog flag on patch
Comment 8 Tom Ware CLA 2011-02-17 15:32:05 EST
Fix backported to 2.1.3
Comment 9 Eclipse Webmaster CLA 2022-06-09 10:05:36 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 10 Eclipse Webmaster CLA 2022-06-09 10:09:36 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink