在Spring Data中通过非主键进行一对一关联的任何方法
我有一种情况,两个实体要在非主键列上连接。我有以下情况:
@Embeddable
Entity EmbeddedKey{
private String apple;
private String banana;
private int cat;
}
@Entity
public class ParentEntity{
@EmbeddedId
private EmbeddedKey embeddedKey;
@Column(name = "dog")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private BigInteger dog;
@OneToOne(mappedBy = "parentEntity")
@JoinColumn(name = "dog", referencedColumnName = "dog")
private ChildEntity childEntitty;
}
@Entity
public class ChildEntity{
@OneToOne
@PrimaryKeyJoinColumn(name = "dog", referencedColumnName = "dog")
private ParentEntity parentEntity;
@Id
@Column(name = "dog")
private BigInteger dog;
}
当我部署代码时,我得到
Caused by: org.hibernate.MappingException: broken column mapping for: ParentEntity.id of: x.y.z.ChildEntity.
按照我的说法,hibernate 正在尝试将父表的主键与我的设计不需要的子表的主键连接起来。由于不可避免的原因,列狗是唯一的,但不是主键。
I have a situation where two entities are to be joined on non-primary key column. I have following situation:
@Embeddable
Entity EmbeddedKey{
private String apple;
private String banana;
private int cat;
}
@Entity
public class ParentEntity{
@EmbeddedId
private EmbeddedKey embeddedKey;
@Column(name = "dog")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private BigInteger dog;
@OneToOne(mappedBy = "parentEntity")
@JoinColumn(name = "dog", referencedColumnName = "dog")
private ChildEntity childEntitty;
}
@Entity
public class ChildEntity{
@OneToOne
@PrimaryKeyJoinColumn(name = "dog", referencedColumnName = "dog")
private ParentEntity parentEntity;
@Id
@Column(name = "dog")
private BigInteger dog;
}
When I deploy code, i get
Caused by: org.hibernate.MappingException: broken column mapping for: ParentEntity.id of: x.y.z.ChildEntity.
As per me, hibernate is trying to join primary key of parent table with primary-key of child table which my design doesn't want. column dog is unique but not primary key due to unavoidable reason.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论