I am using hibernate and spring and I find the this question:
I have a class -> Batch
@Entity @org.hibernate.annotations.Entity(mutable=false) @Table(name="batch") public class Batch {
private Long identifier; private Person sellerParty; ... @SequenceGenerator( // It only takes effect for name="BatchIdGenerator", // databases providing identifier sequenceName="BatchSeq") // generators. @Id @GeneratedValue(strategy=GenerationType.AUTO, generator="BatchIdGenerator") /** * @return the identifier */ public Long getIdentifier() { return identifier; }
/** * @param identifier the identifier to set */ public void setIdentifier(Long identifier) { this.identifier = identifier; } ... /** * @return the sellerParty */ @OneToOne(cascade=CascadeType.ALL) @JoinColumn(name="seller_id") public Person getSellerParty() { return sellerParty; } /** * @param sellerParty the sellerParty to set */ public void setSellerParty(Person sellerParty) { this.sellerParty = sellerParty; } ... package es.corunet.facturgal.model.person;
and the class -> Person... @Entity @Table(name = "person") @Inheritance(strategy=InheritanceType.SINGLE_TABLE) public class Person { private Long identifier; private String personTypeCode; ... @SequenceGenerator( // It only takes effect for name="PersonIdGenerator", // databases providing identifier sequenceName="PersonSeq") // generators. @Id @GeneratedValue(strategy=GenerationType.AUTO, generator="PersonIdGenerator") /** * @return the identifier */ public Long getIdentifier() { return identifier; }
/** * @param identifier the identifier to set */ public void setIdentifier(Long identifier) { this.identifier = identifier; } ... /** * @return the personTypeCode */ public String getPersonTypeCode() { return personTypeCode; }
/** * @param personTypeCode the personTypeCode to set */ public void setPersonTypeCode(String personTypeCode) { this.personTypeCode = personTypeCode; } I have BatchDaoHibernate y PersonDaoHibernate class that extend GenericDaoHibernate with the method public void create(E entity) { getSession().persist(entity); }
Can I do that my aplication calls create if a person whith the same PersonTypeCode exists does not create a new person and use the old?
Thanks
Thanks
|