-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Moving associated objects between parents
PostPosted: Sat Apr 16, 2005 2:09 am 
Newbie

Joined: Fri Jan 14, 2005 8:30 pm
Posts: 11
I've got two tables like so:

Code:
visitors
  VisitorID

addresses
  addressID
  VisitorID

(members is a one to many relationship to visitors)



Snippets from my class/mapping (xdoclet) code looks like so:

Code:
Visitor
/**
     * @hibernate.set lazy="true" inverse="true"
     * @hibernate.collection-key column="VisitorID"
     * @hibernate.collection-one-to-many class="Address"
     */
    public Set getAddresses() { return addresses; }
    public void setAddresses(Set addresses) { this.addresses = addresses; }
    private Set addresses;


Code:
Address
    /**
     * @hibernate.many-to-one
     * @hibernate.column name="VisitorID"
     */
    public Visitor getVisitor() { return visitor; }
    public void setVisitor(Visitor visitor) { this.visitor = visitor; }
    protected Visitor visitor;




This is all working splendidly, nothings broken. Here's my question: What' happens when I do this?:

Code:
Visitor oldVisitor = dao.getVisitor(123);
Visitor newVisitor = dao.getvisitor(234);

newAddresses = newVisitor.getAddresses(); // <---
oldVisitor.setAddresses(newAddresses) // <---

dao.save(oldVisitor)


In other words, what happens if I take an addresses set from my new visitor object (whose addresses have IDs pointing to that *new* visitor record) and simply copy them into my old visitor record and then save.

Is Hibernate smart enough to see that this set need to be "reassociated" with a new object? If yes, does it take the original addresses and rewrite their IDs with an UPDATE statement? Or maybe it just inserts new address records that are duplicates of the original but with appropriate IDs?

Many thanks!

- Gary

Hibernate version:
2.1

Code between sessionFactory.openSession() and session.close():
Using Spring to manage the session

Full stack trace of any exception that occurs:
not applicable

Name and version of the database you are using:
MySQL 4.1.8

The generated SQL (show_sql=true):
not applicable

Debug level Hibernate log excerpt:
not applicable[/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.