1
votes

I have a standard spring/jpa/hibernate setup. A service method with @Transactional that uses two different DAOs with each their own EntityManager instance injected.

When querying, what is ultimately the same entity (directly and indirectly retrieved), they are represented as different objects, even though for the same hibernate session (transaction) they should be the same object.

So are my DAOs using different hibernate sessions, or...?

1

1 Answers

1
votes

The object identities can be different even if the hibernate session is the same. In case you read by identifier using the entityManager.find method the returned objects are always identical in the same session (1st level caching). However using JPQL or criteria query could get you different instances (with the same data).