-->
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: Unidirectional one-to-many
PostPosted: Wed Aug 09, 2006 1:37 pm 
Beginner
Beginner

Joined: Wed Aug 27, 2003 8:55 am
Posts: 28
Location: Dallas, TX
I have seen this issue discussed several times before but I still cannot find a definitive answer...

Basically, we have a unidirectional one-to-many mapping like so:

Code:
public class DraftProfile {
    private Collection<DraftPlan> draftPlans;
    ....
}


Code:
<hibernate-mapping>

    <class name="domain.DraftProfile">

        <bag name="draftPlans" cascade="all,delete-orphan" access="field">
            <key column="profile_id" not-null="true"/>
            <one-to-many class="domain.DraftPlan"/>
        </bag>

</hibernate-mapping>


We add a DraftPlan to a DraftProfile like so:

Code:
// open session and retrieve Profile
profile.addDraftPlan(draftPlan);
save(profile);
// commit


The comment represent functionally what is going on - the transaction and Session management is handled by Spring. Pretty sure this is a mapping issue, so this does not seem to matter.

Anyway, when this is executed, we see two statements, an insert and an update:

Code:
Hibernate:
    insert
    into
        draft_plan
        (draft_type, loan_number, enrollment_channel, status, service_fee, payment_selection_type, payment_amount, late_
charge, principal, escrow, fees_due, credit_life, interest, other_amount, profile_id, start_date, plan_type)
    values
        (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'ONE_TIME  ')
Hibernate:
    update
        draft_plan
    set
        profile_id=?
    where
        plan_id=?


I have an idea of the "why" behind this, as it was documented well at http://www.hibernate.org/hib_docs/v3/reference/en/html/example-parentchild.html#example-parentchild-bidir and http://forums.hibernate.org/viewtopic.php?t=959465.

However, what I still have not found an answer for is can this be solved without having a bidirectional relationship? All solutions I have read simply say add inverse="true", but does this property even have any meaning for unidirectional relationshipts.

What I want is to have a unidirectional relationship in my object model and for Hibernate not to issue an insert after an update when I add to the child collection. Is this possible?


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.