Hello,
I have a class with a map of maps that I want to persist.
public class Foo {
...
Map<PropertyType,Map<Date,String>> properties;
}
(A foo-object has some properties, which are unknown in advance and the history of the value of that property needs to be known/stored)
The idea is to store all properties in one table
Table PROPERTIES
Id <PK>
fooId <FK>
propertyId
Date
Value
To be able to define the hibernate-mapping I introduced a PropertyDTO which represents a row in the table.
Finally i introduced a getter/setter in Foo
public Set<PropertyDTO> getProperties() which creates a list based on the properties-map. (There is no Set instance-field)
(The setters fills the properties-map)
The problem is that when I persist a foo-object every propertyDTO is put TWICE in the table. When I create Set instance-field (and by consequence duplicate the properties in every foo-object), persisting the object works fine...
Can I avoid the duplicate insertion?