Java 如何存储地图<;字符串,列表<;字符串>&燃气轮机;使用JPA

Java 如何存储地图<;字符串,列表<;字符串>&燃气轮机;使用JPA,java,hibernate,jpa,map,Java,Hibernate,Jpa,Map,我正在尝试存储一张地图;使用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; pr

我正在尝试存储一张
地图
;使用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;
    ...
}
将引发以下异常:

org.hibernate.AnnotationException: Illegal attempt to map a non collection as a
@OneToMany, @ManyToMany or @CollectionOfElements: [...]Profiles.AllProfiles

提前感谢

您是否尝试将所有配置文件声明为接口类型(比如Map)?
检查字符串不是实体,所以不应该使用@OneToMany等

你试过这个吗:

@CollectionOfElements
private Map<String, List<String>> allProfiles;
@collectionfements
私人地图资料;

这不是一个真正的答案,但我就是这样做的

我将第二级集合存储为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;
@实体
@表(name=“Profiles\u Table”)
公共班级简介{
@身份证
@列(name=“profile\u ID”,updateable=false,nullable=false)
@GeneratedValue(策略=GenerationType.AUTO)
私有int-id;
@列(长度=16777210)
私有最终HashMap-AllProfiles;

看看这个问题:似乎没有合适的方法。恐怕你必须使用自定义类。谢谢你,我在搜索时错过了它!我将使用allprofile抛出的接口类型进行查看(因为hibernate对接口不好):无法确定:java.util.Map,at table:profiles_table,for columns:[org.hibernate.mapping.Column(所有_配置文件)的类型无法确定:java.util.List,at table:……非常确定这个答案的意思是
@ElementCollection
,它失败时@Nawa提到了相同的错误。
@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;