需要一个 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 尝试为上述映射自动生成架构时,它都会尝试将主键创建为 blob,而不是 long,这是 PaperCheque 的 id 类型.有人能帮帮我吗 ?如果我不能得到一个确切的解决方案,可以做一些接近的事情,但我会很感激任何回应.
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.
相关文章