我是JPA / Hibernate的初学者。我有两个必须在一对一关系中链接的课程。我有这门课:
@Entity
@Table (name = "doc")
public class Document {
@Id
@Basic(optional = false)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "doc_cd_doc_seq")
@SequenceGenerator(name = "doc_cd_doc_seq", sequenceName = "doc_cd_doc_seq")
@Column(name = "cd_doc")
private Long code;
}
当我构造这个时,我想用序列生成器创建他的依赖项(另一个对象,另一个表):
@Entity
@Table (name= "attached_doc_info")
public class AttachedDocInfo {
@Id
@Basic(optional = false)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "attached_doc_info_cd_attached_doc_info_seq")
@SequenceGenerator(name = "attached_doc_info_cd_attached_doc_info_seq", sequenceName = "attached_doc_info_cd_attached_doc_info_seq")
@Column(name = "acd_attached_doc_info)
private Long code;
@JoinColumn(name = "cd_doc", referencedColumnName = "cd_doc")
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE, orphanRemoval = true)
private Document document;
...
}
我的问题是,当我创建Document时,AttachedDocInfo对象不会在他的表中自动创建(attached_doc_info表)。你们能告诉我哪里出错了吗? TY!