JPA Nested Element Collection

user3696953 :

I am trying to figure out if something like this type of Element Collection nesting is possible within JPA? Or at least doing something like this that would not require me to declare a new separate Entity which would hold the inner collection. I have seen usage of @MapKeyColumn & @CollectionTable with java Maps but, am not sure this would help solve.

@Table
@Entity
public class MyClass {
   @Id
   private int myid;

   @ElementCollection
   private Map<String, List<String>> mymap;
}
SternK :

According to the hibernate documentation:

2.8.2. Collections of value types

Collections of value type include basic and embeddable types. Collections cannot be nested, and, when used in collections, embeddable types are not allowed to define other collections.

For collections of value types, JPA 2.0 defines the @ElementCollection annotation. The lifecycle of the value-type collection is entirely controlled by its owning entity.

So, you should declare an intermediate entity to solve your problem.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=397887&siteId=1