Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Hibernate- why my query results are caching?

 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have not set any second level cache.

I am just doing-

Query query = currentSession.createQuery("from Employee v where v.empId=" + empid);

List<Employee> retList = query.list();

and what I was doing is updating one of the employee object. and when I execute the query sometimes it returns update employee in the collection and sometimes old employee in that collection.

can some one help? Thanks,
-Visu
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without further information, including how and when the employee (or employee collection) is being modified I'm not sure how we can help, although someone more familiar with Hibernate might have a better idea.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its not Hibernate that is likely to be doing this. The query cache is pointless without a second level cache. I second David - we need to see more about what you are doing to help. Can you post your code?
 
vishwa venkat
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is more info-

First i go to list screen where I display all employees foa department using-

Query query = currentSession.createQuery("from Employee v where v.deptId=" + deptId);
List<Employee> retList = query.list();

Next I go to particular employee by another query-
Query query = currentSession.createQuery("from Employee v where v.empId=" + empId);
Employee v = (Employee ) query.uniqueResult();

and once the user makes changes to the employee I call update-

Employee v = (Employee ) currentSession.merge(employee);
currentSession.flush();

and then I go back to view the list of employees again-

Query query = currentSession.createQuery("from Employee v where v.deptId=" + deptId);
List<Employee> retList = query.list();

I keep refreshing the list screen sometimes I see the employee with old details sometimes with new details.

I used a HibernateSessionFilter that starts up a session on each servlet request and closes at the end of service the request.

let me know if you need any more details.. I am very confused why its behaving weird...Thanks for all your help!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic