I have a class ClassWithDates
(let's call it "C") which contains a collection of dates
. I have many objects of type C and thousands/millions of date objects, which often refer to the same time.
I'd like to have a pool of date objects, and return an already allocated one if one exists for the time requested. This is quite simple, but when using Hibernate I don't know how to do it.
If I do a "from ClassWithDates" query, and have lazy fetching off, Hibernates loads all the objects of the class ClassWithDates and all the child collections, but, as far as I know, it creates new date objects for each element in the collection, even when the objects are the same.
I'm interested in object pooling with Hibernate for immutable classes. How could I implement it?
The example given above is a simplification of the code I'm working on.