如何使用 JPA 存储 Map<String, List<String>>

Xio*_*caL 5 java dictionary hibernate jpa

我正在尝试存储一个Map<String, List<String>>; 使用 JPA。

我的实体看起来像:

@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;
    ...
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试了很多地图设置,但它不起作用......

我尝试的最后一个:

@ElementCollection
@MapKeyColumn(name = "Profil")
@Column(name = "Permissions")
@CollectionTable(name = "Profiles_permissions", joinColumns = @JoinColumn(name = "profile_ID"))
Run Code Online (Sandbox Code Playgroud)

抛出以下异常:

org.hibernate.AnnotationException: Illegal attempt to map a non collection as a
@OneToMany, @ManyToMany or @CollectionOfElements: [...]Profiles.AllProfiles
Run Code Online (Sandbox Code Playgroud)

提前致谢

Xio*_*caL 1

不是真正的答案,但这就是我所做的。

我将第二级集合存储为 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;
Run Code Online (Sandbox Code Playgroud)