Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem when querying after create or update

 
Naveen Sampra
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have service method call createProduct():

Another service method call listProducts():

The above 2 service calls are made in the same transaction context. i.e. first create the product and get a listing of products.

The problem is, productList listing contains "product1" instance in memory(created from createProduct()) instead of reading corresponding row from DB.
The same happens when a product is edited and then the DB is queried. The query contains the edited object in memory.

How can this happen ? Has anyone encountered this situation. How do I solve this problem.

Note:- I'm using Spring's declarative transaction management. I'm also using OpenSessionViewFilter. Therefore FLUSH_MODE = NEVER.

Any help is appreciated.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are updating and retrieving the object as part of the same session then Hibernate is going to get the object directly from its session (first level cache).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic