需要在Hibernate中的主键@OneToOne映射的例子 [英] Need an example of a primary-key @OneToOne mapping in Hibernate

查看:221
本文介绍了需要在Hibernate中的主键@OneToOne映射的例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以给我在Hibernate中单向@OneToOne主键映射的例子吗?我尝试过多种组合,到目前为止,我已经得到的最好的东西是这样的:

Can somebody please give me an example of a unidirectional @OneToOne primary-key mapping in Hibernate ? I've tried numerous combinations, and so far the best thing I've gotten is this :

@Entity
@Table(name = "paper_cheque_stop_metadata")
@org.hibernate.annotations.Entity(mutable = false)
public class PaperChequeStopMetadata implements Serializable, SecurityEventAware {

private static final long serialVersionUID = 1L;

@Id
@JoinColumn(name = "paper_cheque_id")
@OneToOne(cascade = {}, fetch = FetchType.EAGER, optional = false, targetEntity = PaperCheque.class)
private PaperCheque paperCheque;
}

当Hibernate试图自动生成上述映射的架构,它尝试创建,而不是作为一个长期的,这是PaperCheque的ID类型的主键作为一个blob。有人能帮帮我吗?如果我不能得到一个确切的解决方案,一些接近会做,但我AP preciate任何回应。

Whenever Hibernate tries to automatically generate the schema for the above mapping, it tries to create the primary key as a blob, instead of as a long, which is the id type of PaperCheque. Can somebody please help me ? If I can't get an exact solution, something close would do, but I'd appreciate any response.

推荐答案

您的意图是让PaperChequeStopMetaData和PaperCheque之间的关系,1-1?如果是这样的话,你无法定义PaperCheque实例作为PaperChequeStopMetaData的@Id,你必须PaperChequeStopMetaData定义一个单独的@Id列。

Your intention is to have a 1-1 relationship between PaperChequeStopMetaData and PaperCheque? If that's so, you can't define the PaperCheque instance as the @Id of PaperChequeStopMetaData, you have to define a separate @Id column in PaperChequeStopMetaData.

这篇关于需要在Hibernate中的主键@OneToOne映射的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆