wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Previous replicated result in getResultList() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Previous replicated result in getResultList()" Watch "Previous replicated result in getResultList()" New topic
Author

Previous replicated result in getResultList()

Michael Goossens
Greenhorn

Joined: Dec 06, 2012
Posts: 4
Hello,

I execute this following code two times once with pk = 4754 and once with pk = 4763. The variable result however will both times contain the exact same object, the one with pk 4754. How is this possible? Does JPA keep the previous result in its cache or something?

James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
You seem to be using a ResultSetMapping, most likely an issue with it. Please include it.

Try executing the query without the ResultSetMapping.


TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Michael Goossens
Greenhorn

Joined: Dec 06, 2012
Posts: 4
This is the result mapping

Michael Goossens
Greenhorn

Joined: Dec 06, 2012
Posts: 4
Something strange to note. The date in startDate is the same for both requests. And when I do -1 second on the date(for both requests) the result is correct.
Michael Goossens
Greenhorn

Joined: Dec 06, 2012
Posts: 4
Ok I think I have it. The primary key of the result is actually not unique. When we do -1 second on the date the keys returned in the two calls will be different. When I do not do the -1 second the keys will be the same. So I think JPA will say: "oh the same key" so we do not retrieve the second object, we just return the one in cache.

Is there a way to force a retrieve of the attributes on a getResultList() even if the primary key is the same as one of the objects in memory?
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
You should not use a column as your Id that is not unique.
Instead of getting the entities, you could just get the data with your native query, and build the objects with the data if you need to.

If you are using EclipseLink, you can bypass the persistence context using the query hint, "eclipselink.maintain-cache"="false".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Previous replicated result in getResultList()
 
Similar Threads
NULL POINTER eXCEPTION
Get last 5 days data by HQL
Problem with a MySQL stored procedure calling
eclipselink stored procedures with result returned from different tables
HQL query for multiple conditions met