Hi,
I am using the JBoss Hibernate plug in for eclipse and attempting to reverse engineer my pojos from a mysql database. I have been able to do this with some success and i do see that the one-to-many and many-to-many properties are definied in the hbm files. What is happening however, is if i have pojo that represents a one to many relationship, and i make changes to both tables, only the single 'one' table is updated.
For example, let's say i have a Person and a PersonAddress table that contain foreign key relationships. When i reverse engineer the Pojos from this database, what is created is a Person pojo which also contains a Set of PersonAddress:
public Set<PersonAddress> getPersonAddresses() {
return this.personAddresses;
}
public void setPersonAddresses(Set<PersonAddress> personAddresses) {
this.personAddresses = personAddresses;
}
If i update the Person.name and use hibernate to save that change, all works well.
If i update the name and also add a new address however, the name changes, but the address is not added to the PersonAddress table.
I am wondering if need to individually add the address first or if the above scenario should just work if i create a new PersonAddress, add it to the Person object using the setPersonAddresses method, and simply updating the Person object.
thanks much any help regarding this,
Mark
Seems you didn't map your dependent object(PersonAddress) with cascade="all" or cascade="save-update".
Look here for more details http://samsonov.bn.by/lib/hibernate/manipulatingdata.html
Paragrapf 9.8. Lifecyles and object graphs