-->
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: Problem with multiple many-to-one relations in the parent.
PostPosted: Wed Mar 24, 2004 11:29 am 
Newbie

Joined: Wed Mar 24, 2004 11:13 am
Posts: 15
Location: Norcross, GA
Good Morning

I am using Hibernate 2.1.2 with Spring 1.0RC1 and SQLServer 2000.

I have a domain object HealthInsurance which has 2 attributes of type of MedicalInsurance.

The mapping has entries

-------------------------------------------------------------------
<many-to-one
name="typeOfInsuranceAtDiagnosis"
class="xx.domain.MedicalInsurance"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="INSURANCE_AT_DIAGNOSIS_CODE"
/>

<many-to-one
name="typeOfInsuranceAtEntry"
class="xx.domain.MedicalInsurance"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="INSURANCE_AT_ENTRY_CODE"
/>
-------------------------------------------------------------------


When I try to "save" a newly created HealthInsurance object with both attributes,
// START OF CODE
hi.getTypeOfInsuranceAtDiagnosis().setCode("MCARE");
hi.getTypeOfInsuranceAtEntry().setCode("MCAID");
getHibernateTemplate().save(hi);
// END OF CODE

everything works fine.

If I try to save with only one attribute ,
// START OF CODE
hi.getTypeOfInsuranceAtEntry().setCode("MCAID");
getHibernateTemplate().save(hi);
// END OF CODE

I get the following error:
// STACK TRACE
-------------------------------------------------------------------
org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: xx.dmacs.domain.MedicalInsurance
at org.springframework.orm.hibernate.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:172)
at org.springframework.orm.hibernate.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:203)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:154)
at org.springframework.orm.hibernate.HibernateTemplate.save(HibernateTemplate.java:297)
at xx.dao.DataEntryDAO.storeHealthInsurance(DataEntryDAO.java:104)
at xx.services.DataEntryServices.createHealthInsurance(DataEntryServices.java:111)
at xx.services.HealthInsuranceTest.testAddHealthInsurance(HealthInsuranceTest.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
-----------------------------------------------------------------

I was looking through the Reference Documentation Sec 8.8.1 but there was not much I could relate to this scenario.

Any help/pointers in solving this problem is much appreciated.

Thanks
Madhu


Top
 Profile  
 
 Post subject: save works but not update
PostPosted: Wed Mar 24, 2004 12:41 pm 
Newbie

Joined: Wed Mar 24, 2004 11:13 am
Posts: 15
Location: Norcross, GA
I could save the data in the containing object by setting the update="false" in the many-to-one mappings for both attributes (contained object) in the containing object.

Now, that creates a related problem. I am unable to update these 2 attributes after I create the containing object. The call goes through but the values are not updated.

I am going through 5.1.10 but yet no success.

How are people dealing with this situation?

Thanks
Madhu


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.