How to save map <String, List <String>> using JPA
I am trying to save Map<String, List<String>>
; using JPA.
My object looks like this:
@Entity
@Table(name = "Profiles_table")
public class Profiles {
@Id
@Column(name = "profile_ID", updatable = false, nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private final HashMap<String, List<String>> AllProfiles;
...
}
I tried many settings for the map but didn't work ...
Last thing I tried:
@ElementCollection
@MapKeyColumn(name = "Profil")
@Column(name = "Permissions")
@CollectionTable(name = "Profiles_permissions", joinColumns = @JoinColumn(name = "profile_ID"))
The following exception is thrown:
org.hibernate.AnnotationException: Illegal attempt to map a non collection as a
@OneToMany, @ManyToMany or @CollectionOfElements: [...]Profiles.AllProfiles
early
+3
source to share
3 answers
Not really an answer, but that's what I did.
I am storing the second level of the collection as a blob.
@Entity
@Table(name = "Profiles_table")
public class Profiles {
@Id
@Column(name = "profile_ID", updatable = false, nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Column(length = 16777210)
private final HashMap<String, Set<String>> AllProfiles;
+1
source to share
Have you tried to declare AllProfiles as an interface type (let's say Map)? Check "Illegal Attempted Non-Collection Mapping as @OneToMany, @ManyToMany or @CollectionOfElements" in Hibernate while annotating ConcurrentHashMap
0
source to share