0

Say I want to update entity A which references B but B is a big entity.

If B is not a cached entity (2nd-level), I normally do a getReference() if I have access to B's PK to avoid the extra SELECT query.

Now if B is cached (2nd-level), will getReference() and find() be identical?

Rey Libutan
  • 5,226
  • 9
  • 42
  • 73

1 Answers1

0

If by identical you mean that both would return the same object, then no. find would go the second level cache and return that object whereas getReference would return the object of the first level cache i.e. the persistence context, and if that doesn't exist, return the proxy. Only when initializing the proxy it would try to lookup data from the second level cache.

Christian Beikov
  • 15,141
  • 2
  • 32
  • 58