JPA Map mapping

后端 未结 4 2180
孤城傲影
孤城傲影 2020-12-03 04:53

How can I map a Map in JPA without using Hibernate\'s classes?

4条回答
  •  眼角桃花
    2020-12-03 05:10

    Although answer given by Subhendu Mahanta is correct. But @CollectionOfElements is deprecated. You can use @ElementCollection instead:

    @ElementCollection
    @JoinTable(name="ATTRIBUTE_VALUE_RANGE", joinColumns=@JoinColumn(name="ID"))
    @MapKeyColumn (name="RANGE_ID")
    @Column(name="VALUE")
    private Map attributeValueRange = new HashMap();
    

    There is no need to create a separate Entity class for the Map field. It will be done automatically.

提交回复
热议问题