Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

nested java maps

Garf De Poes
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Id <PK>
fooId <FK>

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?
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic