deplicatemappingException包含物理列名称,该名称由多个逻辑列名在向学生实体添加Passportid上的多个逻辑列名称
该代码在启动上引起以下例外,
Caused by: org.hibernate.DuplicateMappingException: Table [student] contains physical column name [passport_id] referred to by multiple logical column names: [passport_id], [passportId]
我正在使用H2内存数据库。
学生实体:
@Entity
public class Student {
@Id
@GeneratedValue
private Integer id;
@Column(nullable = false, length = 250)
private String name;
private Integer passportId; // adding this will cause DuplicateMappingException
@OneToOne
private Passport passport;
// getters and setters omitted for brevity
}
护照实体:
@Entity
public class Passport {
@Id
@GeneratedValue
private Integer id;
@Column(nullable = false, length = 250)
private String number;
// getters and setters omitted for brevity
}
问题1: org.hibernate.duplicatempappingexception的原因是什么?
问题2:为什么学生实体中的 Passportid 解决问题?
@Column(name = "passport_id", insertable = false, updatable = false)
private Integer passportId; // this resolves DuplicateMappingException
PS:我知道之前已经问过类似的问题,但我无法理解这些其他线程的这两个问题的答案。
This code is causing the following exception on the startup
Caused by: org.hibernate.DuplicateMappingException: Table [student] contains physical column name [passport_id] referred to by multiple logical column names: [passport_id], [passportId]
I'm using H2 in-memory database.
Student entity:
@Entity
public class Student {
@Id
@GeneratedValue
private Integer id;
@Column(nullable = false, length = 250)
private String name;
private Integer passportId; // adding this will cause DuplicateMappingException
@OneToOne
private Passport passport;
// getters and setters omitted for brevity
}
Passport entity:
@Entity
public class Passport {
@Id
@GeneratedValue
private Integer id;
@Column(nullable = false, length = 250)
private String number;
// getters and setters omitted for brevity
}
Question 1: What is the reason for org.hibernate.DuplicateMappingException?
Question 2: Why does adding the following annotation to passportId in the Student entity resolve the issue?
@Column(name = "passport_id", insertable = false, updatable = false)
private Integer passportId; // this resolves DuplicateMappingException
PS: I know similar questions has been asked earlier but I couldn’t understand the answer for these two questions from those other threads.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案1
原因是您对同一数据库列有两个可写的映射,并且不允许
答案2
使其中一台映射仅读取解决问题,因为这样只有一个映射将是可写的
Answer 1
The reason is that you have two writable mappings for the same database column and this is not allowed
Answer 2
Making one of the mappings read-only solves the problem because then only one mapping will be writable