[jboss-user] [JBoss Tools] - Hibernate Tools - How to handle updates to one-to-many property

Mark S. do-not-reply at jboss.com
Wed Dec 1 22:29:38 EST 2010


Mark S. [http://community.jboss.org/people/dizzy0ny] created the discussion

"Hibernate Tools - How to handle updates to one-to-many property"

To view the discussion, visit: http://community.jboss.org/message/573982#573982

--------------------------------------------------------------
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;
    }
     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
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/573982#573982]

Start a new discussion in JBoss Tools at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2128]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20101201/d50558c2/attachment.html 


More information about the jboss-user mailing list