gpt4 book ai didi

java - 我在@OneToMany hibernate 映射中遇到错误?

转载 作者:行者123 更新时间:2023-11-29 07:32:19 25 4
gpt4 key购买 nike

我试图在两个类之间建立一对多连接,但我收到此错误 org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany

这是我的代码,

Job.java

@OneToMany
@JoinColumn(name = "id", referencedColumnName = "id", insertable = false, updatable = false)

private Set<JobCostSplit> jobCostSplit;

JobCostSplit.java

@Column(name = "job_id")
private Long jobId;

@JsonIgnore
@OneToMany
@JoinColumn(name = "job_id", referencedColumnName = "id", insertable = false, updatable = false)
private Job job;

最佳答案

您使用 @OneToMany 注释您的 Job。意味着您将在 Job 上拥有一个属性,在 JobCostSplit 上拥有更多属性。

所以如果你想要一个Job和多个JobCostSplit,你必须这样设置:

@ManyToOne
@JoinColumn(name = "job_id", referencedColumnName = "id", insertable = false, updatable = false)
private Job job;

关于java - 我在@OneToMany hibernate 映射中遇到错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40483589/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com