Hi,
I have:
Code:
@Entity
@Table(name="persons")
@Inheritance(strategy=InheritanceType.JOINED)
class Person {
long id;
String name;
...
}
@Entity
@Table(name="fiancees")
class Fiancee extends Person {
boolean isWoman;
...
}
@Entity
@Table(name="fiancee_pairs")
class FianceePair {
Fiancee fianceeHe = new Fiancee();
Fiancee fianceeShe = new Fiancee();
@ManyToOne(optional=true)
@JoinColumn(name="fiancee_he_id", nullable=true)
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE,CascadeType.PERSIST})
public Person getFianceeHe() {
...
@ManyToOne(optional=true)
@JoinColumn(name="fiancee_he_id", nullable=true)
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE,CascadeType.PERSIST})
public Person getFianceeShe() {
...
}
I have a form in which I set some fields of FianceePair. Firstly in my form controller I am loading objects of Person class and make corresponding object of Fiancee class, which have fields just like the Person objects (also the id). Notice that I have Person records in the database but I do not have Fiancee records in the database.
In the form I am setting isWoman field of Fiancee objects.
When I am submitting the form I can see in my onSubmit method that I have a FianceePair object with two Fiancee objects with some id (the id from exisiting Person objects). Now I would like to save the FianceePair in the way that new records of Fiancee class will be created in the database with Person records remain unchanged.
The getHibernateTemplate().merge(fp) method of my FianceeDaoHibernate ends with creating Fiancee records as well as new Person records - and these new Person records are undesirable for me.
So before the operation I have two records in my persons table: (1, 'Alice') (2, 'Peter')
After the operation I have four records in my persons table: (1, 'Alice') (2, 'Peter') (3, 'Alice') (4, 'Peter') and two records in fiancees table (3, 1) (4, 0)
Could someone point me to the right direction?
Best Regards,
Gandalf