Saving JPA2 for @ManyToMany map containing set

I need to save an element with type Map<Item, Set<Item>> using JPA2 annotations. The relationship is many for many, and Item objects are entities.

Should I create a separate intermediate Entity object containing Set<Item> or is direct matching possible?

Please indicate if any context is missing.

+6
java orm jpa
source share
1 answer

Should I create a separate intermediate Entity object containing Set<Item> , or is direct matching possible?

JPA does not support nested collection relationships ( List of List s, Map of Set s, etc.). Here is the relevant section of the Map specification:

2.7 Card Collections

Collections of elements and relationship objects can be represented as java.util.Map.

The card key and the value of the card, independently of each other, can be a base type, nested class or legal entity.

...

So yes, use an object containing Set<Item> , and then map your relation as Map<Item, MyHolder> .

References

+6
source share

All Articles