• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Previous replicated result in getResultList()

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You seem to be using a ResultSetMapping, most likely an issue with it. Please include it.

Try executing the query without the ResultSetMapping.
 
Michael Goossens
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the result mapping

 
Michael Goossens
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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".
 
reply
    Bookmark Topic Watch Topic
  • New Topic