When I load() an object hibernate return me a proxy object and when I get() an object hibernate return me a new instance of this object.
But If I have for example: One Exercise has many Categories and One Category has many Exercises and there are 4 categories that always are same: A, B, C, D
When I get an Exercise with its category, e.g. A and then get other with A too.
Have I two instances of A? Because A is the same for all exercises. How can I share the same reference for all Exercises?
Hibernate’s Session ensures that no duplicated objects are loaded. You’ll have several references to the same objects.
If you loaded the same object twice in 2 sessions and then you’re trying to save both in a single session, you’ll get an exception that would state that there are 2 same object associated with the session.