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

Concurrent session and caching

 
Devendra Thomare
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ,

I am new to hibernate .I want to know how caching is working in 1st level

suppose i have 2 sessions running concurrently

suppose
1st session

1. load the Person object
and then
2. update the person object

since my 2nd thread is also running concurrently

2nd session
1. Load the same Person Object (This Person object will be in its session cache )
2. // inbetween this session1 has updated person object
3. now session 2 again load the person object as per my understanding it will fetch data from its cache

so my doubt is

will session 2 get stale data ?
or session 2 will not load data from its cache if yes why
or session 2's cache will be updated when session 1 updates Person object

Could ypu please answer these questions?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

1. Load the same Person Object (This Person object will be in its session cache )

No, it wont. It has been loaded in to Session 1, not Session 2. You'll get the object from the database.
 
Devendra Thomare
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply

But it has already been loaded in session 2

then was updated by session 1

and again in session 2 it was loaded so what will be the output

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
State is not synchronized between sessions, the object exists in a single session in the state it was loaded.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic