0

There is scenario in my application:
1. I get objects from database:

hql = "some hql query";
Query query = session.createQuery(hql);
return query.list();

2. User makes changes on this object.
3. User is not pleased with changes and wants to reload DB version of objects. (kind of 'abort edit' action)

This is where I hit the wall. When I try to get objects second time hibernate gives me references to the same objects that are already in memory - I can tell that by comparison objects id in debug mode. But these objects in memory are changed in comparison to DB version.
How could I force hibernate to read object from DB instead of giving me reference to already changed version in memory?

Michał Herman
  • 3,437
  • 6
  • 29
  • 43

1 Answers1

1

From Java Persistence 2.0 specification:

3.2.5 Refreshing an Entity Instance

The state of a managed entity instance is refreshed from the database by invoking the refresh method on it or by cascading the refresh operation.

Valentin Jacquemin
  • 2,215
  • 1
  • 19
  • 33