[hibernate-issues] [Hibernate-JIRA] Created: (HHH-5170) Used unsaved-value="any" for <composite-id>, Getting exception Object references an unsaved transient instance - save the transient instance before flushing, even though record exist in the DB

Deepesh Seetharaman (JIRA) noreply at atlassian.com
Wed Apr 28 06:12:00 EDT 2010


Used unsaved-value="any" for <composite-id>, Getting exception Object references an unsaved transient instance - save the transient instance before flushing, even though record exist in the DB
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

                 Key: HHH-5170
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5170
             Project: Hibernate Core
          Issue Type: Bug
          Components: core
    Affects Versions: 3.2.3
         Environment: DB2-z Series, Weblogic 10.3 App Server.
            Reporter: Deepesh Seetharaman
         Attachments: EventService.hbm.xml, State.hbm.xml, test.zip

I have attached the following files.
i)EventService.hbm.xml
ii)State.hbm.xml

While I am trying to persist, EventService, by setting the State object, with only its id fields its giving the folloiwing exception.

org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: com.fareis.las.css.sys.rf.domain.State; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.fareis.las.css.sys.rf.domain.State
Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.fareis.las.css.sys.rf.domain.State
	at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:219)
	at org.hibernate.type.EntityType.getIdentifier(EntityType.java:397)
	at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:242)
	at org.hibernate.type.TypeFactory.findDirty(TypeFactory.java:576)
	at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:3121)
	at org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:472)
	at org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:197)
	at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:120)
	at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
	at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
	at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
	at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
	at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
	at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
	at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:849)
	at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:372)
	at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:840)
	at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:836)
	at com.fareis.core.pf.repository.hibernate.GenericHibernateRepository.findByProperty(GenericHibernateRepository.java:417)
	at com.fareis.las.prc.clb.el.repository.hibernate.EventHibernateRepository.findByClientBillingEventKey(EventHibernateRepository.java:42)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:296)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:177)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
	at $Proxy1.findByClientBillingEventKey(Unknown Source)
	at com.fareis.prc.clb.repository.test.BillableEventRepositoryTestCase.testAddEvent(BillableEventRepositoryTestCase.java:83)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at junit.framework.TestCase.runTest(TestCase.java:164)
	at junit.framework.TestCase.runBare(TestCase.java:130)
	at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
	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:120)
	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)





I am creating the instance like this.

        EventService service = new EventService();
        State state = new State();
        StateId id = new StateId();
        id.setStateCode("DAS");
        Country country = new Country();
        country.setCountryCode("US");
        id.setCountryCode(country);
        state.setId(id);
        service.setBillingId(10);
        service.setStatusCode("A");
        service.setState(state);
        service.setClientBillingEventKey(clientBillingEvent);
        service.setLastUpdateSourceId("TEST");
        service.setLastUpdateTimestamp(new java.util.Date());
        service.setLastUpdateUserId("sdeepesh");
        service.setCorrDate(new Date(System.currentTimeMillis()));

        service.set ... other not-null fields.

State.hbm.xml's <id  property is using unsaved-value="any", if you remove that attribute everything works fine, but it will fire a SELECT SQL to the STATE table, to verify the integrity of the <id>. 

We had explicitly mentioned the unsaved-value="any", in order to prevent the SELECT being fired.

Ironicall I found out that when you make unsaved-value="none", everything works perfectly, but then unsaved-value is having this unpredictable behaviour about it's value.

We are using unsaved-value attribute for all <id, <composite-id which has <generated-class as "assigned", the values are like below
<id unsaved-value="id_value" - id is a String
<id unsaved-value="none" - id is a Integer
<composite-id unsaved-value="any" 

For composite-id everywhere we used, unsaved-value="any", the only contradicting place where we found is with State.hbm.xml

If possible please provide some guidelines as to use the "unsaved-value", we mainly used that to prevent the SELECT SQLs from executing before performing INSERT.


Also while debugging through the hibernate code, I found that it is performing dirtyCheck for EventService instance, where it compares loaded value and current value.

I found that loaded value was having State object as null.

Please provde your comments.

I have also attached the test cases, but you wont able to run it, due to compilation problems, 
testAddEvent is the one which is failing

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list