-->
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.  [ 2 posts ] 
Author Message
 Post subject: Mapping with column used more then once
PostPosted: Wed Feb 01, 2006 6:58 pm 
Newbie

Joined: Wed Feb 01, 2006 6:35 pm
Posts: 1
Hibernate version:
3.1
Mapping documents:
important part
Code:
   <many-to-one
        name="Country"
        class="com.RCountry"
        cascade="none"
    insert="false" update="false" lazy="false" fetch="join">
        <column name="COUNTRY" />
    </many-to-one>
    <!-- uni-directional many-to-one association to RCounty -->
    <many-to-one
        name="County"
        class="com.RCounty"
        cascade="persist,merge,save-update"
   lazy="false" fetch="join">
        <column name="COUNTRY"/>
        <column name="PROVINCE_STATE" />
        <column name="COUNTY" />
    </many-to-one>
    <!-- uni-directional many-to-one association to RProvinceState -->
    <many-to-one
        name="ProvinceState"
        class="com.RProvinceState"
        cascade="none"
    insert="false" update="false" lazy="false" fetch="join">
        <column name="COUNTRY" />
        <column name="PROVINCE_STATE" />
    </many-to-one>

Code between sessionFactory.openSession() and session.close():
session = SessionFactory.newSession();
trx = session.beginTransaction();
Code:
      
[b]//Part1[/b]
RProvinceStatePK provinceStatePK = new RProvinceStatePK();
provinceStatePK.setCountry("US");
provinceStatePK.setProvinceState("42");
RProvinceState provinceState = new RProvinceState(provinceStatePK);
         
[b]//Part 2[/b]
RCountyPK countyPK = new RCountyPK("US", "65", "5");
RCounty county = new RCounty(countyPK);
         
WellHeader wellHeader = new WellHeader();
wellHeader.setUwi("1234567890");
wellHeader.setProvinceState(provinceState);
wellHeader.setCounty(county);
session.saveOrUpdate(wellHeader);
trx.commit();

Full stack trace of any exception that occurs:
NA
Name and version of the database you are using:
Oracle
The generated SQL (show_sql=true):
NA
Debug level Hibernate log excerpt:
NA

When I save the WellHeader by only calling wellHeader.setProvinceState the country and state codes are not updated in the database. I understand that this is because of the insert="false" and update="false" in the mappings, but these two attirbtues must be added because the columns are used more then once in the mapping. By saving County which contains Country and ProvinceState the table is updated. My quesiton is if the user only calls setProvinceState and/or setCountry then the values will not be saved to the database ... how do i fix this? Must I add code in setProvinceState and setCountry to call setCounty? What happens is the user sets

provinceState.setRemark("Hello World")
wellHeader.setProvinceState(provinceState)
session.saveOrUpdate(wellHeader)

I need to be able to save everything; meaning when Isave the wellHeader I Hibernate must save/update the ProvinceState, Country and County objects


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 7:42 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
In the ProvinceState relationship, change <column name="COUNTRY"/> to <formula>COUNTRY</formula>. In the County relationship, do the same thing, and change column name="PROVINCE_STATE" /> to <formula>PROVINCE_STATE</formula>. Each column may be mapped once only.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.