Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JPQL join and collection association (ManyToOne join returning too much in Collection association)
JPQL join and collection association [message #733915] Wed, 05 October 2011 23:23 Go to next message
tbianchi  is currently offline tbianchi Friend
Messages: 4
Registered: November 2010
Junior Member
I have a simple JPQL query (below) and I have 2 entities, PrintDocumentsInfo (the owner) and PrintItemInfo (the reverse); I have the ManyToOne mapping in the PrintDocumentsInfoList entity and the OneToMany mapping in the PrintItemInfo entity.

The fields and annotations are also below.

This query works. However, the Collection<PrintDocumentsInfo> in the PrintItemInfo class is not limited to PrintDocumentsInfo adviceStatus2 = 100.

Unfortunately, I get a Collection of all adviceStatus2 values whenever there is an adviceStatus2 == 100 in the any of the ForeignKeys that relate back to the PrintItemInfo table.

This seems so straightforward in the docs, tutorials, and books but no way can I get this to return the correct results. What am I missing?

Thanks in advance for you helpl



//the jpql join query
String jpqlString3 = "SELECT docs " +
"FROM PrintItemInfo info INNER JOIN info.printDocumentsInfoList docs " +
"WHERE docs.adviceStatus2 = 100 "
;


//this is the "owning" side of the relationship in the PrintDocumentsInfo class
@ManyToOne(targetEntity=PrintItemInfo.class)
@JoinColumn(name="PRINT_ITEM_ID2", referencedColumnName="PRINT_ITEM_ID")
private PrintItemInfo printItemInfo;


//this is the "inverse" side in the PrintItemInfo class
@OneToMany(targetEntity=PrintDocumentsInfo.class, mappedBy="printItemInfo")
private Collection<PrintDocumentsInfo> printDocumentsInfoList
= new TreeSet<PrintDocumentsInfo>();
Re: JPQL join and collection association [message #734078 is a reply to message #733915] Thu, 06 October 2011 15:36 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

That is odd. I would expect that if you selected the info and accessed the docs, but selecting the docs seems like you would only get the filtered ones back.
What was the SQL that was generated?

You could try:
"SELECT docs FROM PrintDocumentsInfo docs WHERE docs.adviceStatus2 = 100 "


James : Wiki : Book : Blog : Twitter
Re: JPQL join and collection association [message #734108 is a reply to message #734078] Thu, 06 October 2011 17:37 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1039
Registered: July 2009
Senior Member
I believe what is being said is that the query is correctly returning docs that reference a docs.adviceStatus2 = 100. What is being stated is that the returned and so managed PrintItemInfo's 1:M collection of PrintDocumentsInfo is fully populated and not filtered based on the query.

If so, this is as expected. The query is to give back fully populated PrintDocumentsInfo. All references will contain all the information associated to the entities as they exist in the database. So the PrintItemInfo's referenced from these returned PrintDocumentsInfo must be full populated and not use the criteria from the query, as doing so would corrupt the cache - these entities are managed so other queries in the same EntityManager context are expected to return the same instance.

My suggestion would be not access the PrintItemInfo's collection so that it remains untriggered, and just used the collection of PrintDocumentsInfo entities returned from the query directly, sorting them by their PrintItemInfo.

[Updated on: Thu, 06 October 2011 17:38]

Report message to a moderator

Previous Topic:Duplicate strings in o.e.p.internal.jpa.metadata.accessors.objects.MetadataClass
Next Topic:@Array doesn't seem to support basic types
Goto Forum:
  


Current Time: Sun Dec 21 17:22:07 GMT 2014

Powered by FUDForum. Page generated in 0.02601 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software