1

Session Factory:

hibernate.current_session_context_class=jta
hibernate.cache.use_second_level_cache=false

Transaction: - UserTransaction is used.

getCurrentSession() of SessionFactory is used to get Session.

The problem is that I could not force the hibernate to access database to get the new values using Session.get(...) (it is updated outside) although I used Session.clear() or Session.evict(…) or Session.refresh(…), SessionFactory.evict(...).
It always kept the old values.

Do you have any idea?

frictionlesspulley
  • 11,070
  • 14
  • 66
  • 115
Catherine
  • 11
  • 2
  • Are you sure that transaction that updates values "outside" is comitted? – axtavt Sep 28 '11 at 19:55
  • Yes, it is committed. I have tried to query it from the other SQL client. – Catherine Sep 29 '11 at 07:07
  • One strange thing was that when I tried to clear() or evict(), the item was removed in the current Session according to my debug(then I committed the transaction). However when my program call "get" in another transaction, it still did not access the new one from database :-S. Any possible causes AXTAVT? - TNX! – Catherine Sep 29 '11 at 07:10
  • @Cathernie: Do you understand that `get()` returns a lazy proxy and don't access the database immediately. If you need immediate access, use `load()` instead. – axtavt Sep 29 '11 at 08:44
  • ASAIK get() returns the actual object and not a proxy, and load() returns a proxy and throws an exception when it can't the object in cache (if used) and database.[Refer: http://stackoverflow.com/questions/608947/hibernate-difference-between-session-get-and-session-load] @Catherine did you evict the instance of the object or the class – frictionlesspulley Sep 29 '11 at 21:25

1 Answers1

0

session.flush() --- will flush your memory update in db. session.clear() will clear session.

Now query again will fire on database.

Piyush Aghera
  • 965
  • 7
  • 13