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
|
|