-->
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.  [ 5 posts ] 
Author Message
 Post subject: Bidirections one-to-many not inverse end
PostPosted: Wed Jul 20, 2005 1:28 pm 
Newbie

Joined: Tue Jul 19, 2005 9:19 am
Posts: 7
I have two classes mapped via a bidirectional one-to-many mapping. The parent is the domain model that can be accessed by many users (the children).

I when the user logs in I am able to retrieve the correct domain object and save the id. This id is then used to load the object up for each request at the end of which it is attempted to be saved.

This is where the problem occurs, the domain object even though fully populated will not persist itself to the data base. I then checked all the mappings and wrote some unit tests outside the app to check how if it works.

My first test saves a new domain object (with no users) to the database and loads its back.This works correctly all values are saved.

My second test retrieves a domain object with at least one user, change some fields and try to save it but this fails. Therefore I was lead to believe that it was something to do with the bidirectional one-to-many mapping.

I RTFM'd and came across http://www.hibernate.org/hib_docs/refer ... tions.html which says that
Quote:
Changes made only to the inverse end of the association are not persisted.


I assumed that this was the cuase of my problem and looked into implementing either Lifecycle or Interceptor to resolve this.

I am correct in this assumption and is this the correct way to procede.

Thanks for any help...
:)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 1:45 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Mapping files and code between session open and close would help a lot.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 4:04 am 
Newbie

Joined: Tue Jul 19, 2005 9:19 am
Posts: 7
The user...
Code:
<class name="eg.User" table="USER" >
   <cache usage="transactional" />
   <id name="id" type="long" column="HIBUSER_ID" unsaved-value="0">
      <generator class="native"/>
   </id>
   <property name="name" column="USERNAME" type="string"/>
   <many-to-one name="domainObject" class="eg.DomainObject" cascade="save-update"    column="pensionSchemeReturn"
   ...
</class>


The domain object

Code:
<class name="eg.domainObject"  dynamic-update="true" dynamic-insert="false"
        select-before-update="false">
        <cache usage="transactional" />
        <id name="domainObjectId" column="domainObjectId" type="java.lang.Integer">
            <generator class="native">         
            </generator>
        </id>
        <version
            name="version"
            type="int"
            column="version"
            access="property"
            unsaved-value="undefined"
        />
        <set
            name="users"
            lazy="true"
            inverse="true"
            cascade="save-update"
            sort="unsorted"
        >
             <key column="pensionSchemeReturn"></key>
              <one-to-many                                               
                 class="eg.User"
              />
        </set>
       ...
</class>


I have tried vairous things to svae the information but the first was this

Code:
DomainObject do = doManager.findDomainObject(new Integer(320));
do.getDetails().getAddress().getAddressLine1().setValue("line1");
do.getDetails().getAddress().getAddressLine1().setValue("line2");
doManager.saveDomainObject(do);



Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 4:20 am 
Newbie

Joined: Tue Jul 19, 2005 9:19 am
Posts: 7
Those were a cut down version of the mapping files, the domain object is a large-ish tree structure of objects beneath it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 5:52 am 
Newbie

Joined: Tue Jul 19, 2005 9:19 am
Posts: 7
Ok I have been looking into this a lot more and its only certain fields that wont save.
In our structure we have a domainObject which has a details object which has a address object.
Fields in the domain object that sare strings save, this is also true for the deails, but in the adress about they do not save. Here are the mappings.

Code:
<class
        name="eg.Domain"
        dynamic-update="true"
        dynamic-insert="false"
        select-before-update="false"
    >
....
<many-to-one
            name="pensionSchemeDetails"
            class="eg.Details"
            cascade="save-update"
            outer-join="auto"
            update="true"
            insert="true"
            access="property"
            column="pensionSchemeDetails"
        />
....
</class>


Details
Code:
    <class
        name="eg.Details"
        dynamic-update="false"
        dynamic-insert="false"
        select-before-update="false"
    >
   ...
        <many-to-one
            name="address"
            class="eg.PostalAddress"
            cascade="save-update"
            outer-join="auto"
            update="true"
            insert="true"
            access="property"
            column="address"
        />
</class>


Address with one of the example lines that is not saving

Code:
<class
        name="eg.PostalAddress"
        dynamic-update="false"
        dynamic-insert="false"
        select-before-update="false"
    >

<property
            name="addressLine1"
            type="eg.ErroredStringType"
            update="true"
            insert="true"
            access="property"
        >
            <column
                name="addressLine1"
                length="35"
            />
            <column
                name="addressLine1Error"
            />
</property>


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

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.