-->
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: insert-update-delete with one-to-many
PostPosted: Wed Nov 03, 2004 12:33 pm 
Beginner
Beginner

Joined: Fri Oct 15, 2004 4:54 pm
Posts: 32
Hibernate version: 2.1.6

Mapping documents:
from User:
Code:
    <set name="reviewers" lazy="false" inverse="true" cascade="all-delete-orphan">
        <key>
            <column name="USER_ID"/>
        </key>
        <one-to-many
            class="tess.Reviewer"
        />
    </set>
    <set name="reviewing" inverse="true">
        <key>
            <column name="USER_ID" />
        </key>
        <one-to-many class="tess.Reviewer"/>
    </set>


from Reviewer:
Code:
    <composite-id>
      <key-many-to-one name="user"
         class="tess.User" column="USER_ID"/>
      <key-many-to-one name="reviewer"
         class="tess.UserProfile" column="REVIEWER_ID"/>
    </composite-id>   


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):
Hibernate: update USER set NAME=? where USER_ID=?
Hibernate: update REVIEWER set TYPE=? where USER_ID=? and REVIEWER_ID=?

Debug level Hibernate log excerpt:


i have a relationship where someone generating reports can have a reviewer for that report. there are different types of reports, and the user can have a different reviewer for each type (or none)

the thing i am seeing is when i first add a reviewer (by adding to the set in the java object), the sql generated does an update instead of an insert.

so i am wondering how hibernate does this. assuming i have a java.util.Set of reviewers, and i add some, remove some, and modify some, when i saveOrUpdate the user how does hibernate know which ones need inseting/deleting/updating?


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.