gpt4 book ai didi

java - Intellij IDEA @OneToMany mappedBy属性错误解决

转载 作者:行者123 更新时间:2023-12-05 01:18:43 24 4
gpt4 key购买 nike

我有点小问题JPA 中的 @OneToMany(mappedBy = "table_name") 注释。所以我们有 2 个表(屏幕截图中的所有详细信息)我添加了一个数据源,但我仍然有错误“无法解析属性”

我能以某种方式解决它吗?

@Id
@Column(name = "state_id")
public int getStateId() {
return stateId;
}

public void setStateId(int stateId) {
this.stateId = stateId;
}

@Basic
@Column(name = "description")
public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

@Basic
@Column(name = "systemname")
public String getSystemName() {
return systemName;
}

public void setSystemName(String systemname) {
this.systemName = systemname;
}

@OneToMany(mappedBy = "note_states")
public Set<Note> getNotes() {
return notes;
}

public void setNotes(Set<Note> notes) {
this.notes = notes;
}

My problem

最佳答案

mappedBy 属性值不应是表名。在双向关联中,它应该是映射关联的另一个实体中的属性名称。

例子:

public class Country {
// ...

@OneToMany(mappedBy = "parentCountry");
private Set<City> cities;
}

public class City {
// ...

@ManyToOne
@JoinColomn(name = "country_id")
private Country parentCountry;
}

关于java - Intellij IDEA @OneToMany mappedBy属性错误解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43303691/

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