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