我试图创建一个包含整数列表的类
@Table(name = "kidding")
@SecondaryTable(name = "kids_list")
public class Kidding {
@Id
@GeneratedValue
@Column(name = "kiddingID")
private long kiddingID;
@Column(name = "doeID")
private int doeID;
@Column(name = "buckID")
private int buckID;
@Column(name = "fertilityDate")
private Date fertilityDate;
@Column(name = "kiddingDate")
private Date kiddingDate;
@ElementCollection
@CollectionTable(name="kids_list", joinColumns=@JoinColumn(name="kiddingID"))
@Column(name = "kidID")
private List<Integer> kidIDs;
@Column(name = "notes")
private String notes;
@Column(name = "ownerID")
private long ownerID;
我有两张table:开玩笑的table和孩子们的table
“开玩笑”有一个主键kiddingid,“孩子”列表有一个外键连接到“开玩笑”的主键
table开玩笑:
儿童ID(pk)Doeiduckid123268358479
表1\u列表:
基丁基德(fk)基丁基德111213244546372839
最后,我想在对象中填充整数列表,如下所示:
When I get kidding 1:
List<Integer> kidsID {1,2,3}
When I get kidding 2:
List<Integer> kidsID {4,8}
When I get kidding 3:
List<Integer> kidsID {7,9}
When I get kidding 4:
List<Integer> kidsID {5,6}
有没有办法用hibernate来做到这一点?
atm我只在有1个孩子的情况下获得孩子id,但如果有2个孩子,我会得到以下错误:
org.hibernate.HibernateException: More than one row with the given identifier was found: 2, for class: com.GoatPool.goatpool.model.Kidding
如果问题或其他东西不清楚,请说出来。如果需要的话,我想详细解释一下!
1条答案
按热度按时间sqxo8psd1#
删除
@SecondaryTable
. hibernate orm已经知道存在一个二级表,因为@ElementCollection
.@SecondaryTable
如果一个实体的属性分布在多个表中,则使用。这不是您的情况,因为您在另一个表中Map的是一个关联。