This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes nested java maps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "nested java maps" Watch "nested java maps" New topic
Author

nested java maps

Garf De Poes
Greenhorn

Joined: Jun 05, 2009
Posts: 2
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: nested java maps
 
Similar Threads
hashCode/equals stratgy for mutable object
EJB with multiple MapKeys
Mapbacked forms
mazed by the relationship between flight and date
"No identifier specified" when using InheritanceType.JOINED