Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

nested java maps

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
CAUTION! Do not touch the blades on your neck propeller while they are active. Tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic