I'm using Joda Time DateTime to handle date and time. I persist objects of this kind using the class PersistentDateTime bundled in the jodatime hibernate code.
I have large collections of DateTime objects, and I currently persist them in the following way (an excerpt of an hibernate mapping file follows):
<set name="validInstants" sort="natural">
<key column="myobject_id"/>
<element column="date" type="myproject.utilities.hibernate.types.PersistentDateTime"/>
</set>
Doing so, i.e. storing DateTimes as value types, I get many duplicate elements in the table validInstants, hundreds of thousands of them. I'd like to avoid this and have in the validInstants table the DateTimes needed, stored once per value. How can I achieve this?
As far as I know (I'm and Hibernate beginner) the only way to achieve this is by creating a class that wraps a DateTime and maps it as an entity, plus creating a factory which returns always the same DateTime-wrapper when asking for the same Date. Is this the best way to do what I want? Suggestions?