java - 具有不同列主键和外键的 HQL ManyToOne
问题描述
我查看了其他人的其他类似问题,但每个给定的答案似乎都不适合我。
我有这个“机构”实体:
@ManyToOne
@JoinColumn(name = "regionId", referencedColumnName = "id")
private Region region;
'institution' 有regionId
并且实体 'region' 有一个id
. 与数据库中的名称完全相同。但这给了我一个org.hibernate.QueryException: could not resolve property: region
错误。
我使用的查询:Query q = session.createQuery("from Institution where id = :id");
数据库具有正确的列设置的适当关系。
编辑:
区域类代码:
@Entity
@Table( name = "region" )
public class Region {
@Id
@Column(name="id")
private Long id;
@OneToMany(mappedBy="region")
private List<Institution> institutionList = new ArrayList();
解决方案
对于双向 OneToMany 映射使用:
@OneToMany(mappedBy="region")
private List<Institution> institutionList = new ArrayList();
推荐阅读
- reactjs - 将 React Native Youtube 组件放置在 React Navigation 中的问题
- javascript - 如何对每个请求进行速率限制
- javascript - 反应 onMouseEnter 正在阻止 onClick
- java - Java浮点数并创建正确的格式
- python - --single-version-externally-managed 无法识别,尽管 setuptools 和轮子是最新的
- java - 如何编码/解码另一个整数中2个整数的所有组合
- javascript - 使用意外的 prevChildKey 参数调用实时数据库事件 child_added
- r - plot_model(type="diag") 中的错误:参数暗示不同的行数错误
- pcap - 对于lib pcapplusplus,为什么ipv6地址没有matchSubnet()
- mysql - SELECT 语句中 mysql 函数的奇怪行为