我想在数据库中保存一行 Penatu。我有三个实体。
我必须创建三个实体吗?或者我可以只使用一个实体对象来设置另一个要保存的属性吗?
@Entity
@Table(name="PE_NATU")
public class PeNatu{
private long peNatuId;
private String apeMat;
private String apePat;
private Persona persona;
..................
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="PE_NATU_ID", unique=true, nullable=false)
public long getPeNatuId() {
return this.peNatuId;
}
etc .....
@Entity
@Table(name="PERSONA")
public class Persona {
private long personaId;
private Set<PeNatu> peNatus;
private TmDocIden tmDocIden;
etc .....
@Entity
@Table(name="TM_DOC_IDEN")
public class TmDocIden{
private String tipoDocId;
private Set<Persona> personas;
etc....
这个对吗?
//Class Service- Impl
PeNatu admin=new PeNatu();
admin.setApePat("Test");
admin.setApeMat("Test");
admin.getPersona().setPersonaId(7777)
admin.getPersona().getTmDocIden().setTipoDocId("05");
long idInserted= dao.insertarPeNatu(admin)
插入 id 是否正确,我使用 oracle DB?
//DAO -Impl
public long insertarPeNatu(PeNatu p) {
Session session = sessionFactory.getCurrentSession();
session.persist(p);
session.flush();
return p.natu.getPeNatuId();
}