• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mapping Maps

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following (stripped down) entity:


I'm trying to figure out how to annotate the values Map. I've tried CollectionOfElements but that only seems to work if both key and value are non-entity objects like String, Integer, etc. I'm going that elsewhere and it works fine. I also tried a @OneToMany with an @MapKey however, the key in my case is not the target entity property.

Note also that StoredReportScheduleMetricValue is an Entity as well and has its own set of properties that need to be persisted.

The reason I am using a Map instead of a list is because I can't guarantee order so indexed properties won't work correctly when the data is loaded back up.

Any help is appreciated.
 
Vijay Dharap
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg Bolinger wrote:
The reason I am using a Map instead of a list is because I can't guarantee order so indexed properties won't work correctly when the data is loaded back up.

Why Map then? You need to replace list with a no order specified.. you should use java.util.Set, Right?

If you must use Map for some other reason, think about how you going to persist your relation.. Not very clear as to what you want to persist in the related table.. May be an example would help understand your question..

HTH,
Vijay
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic