[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2097) LAZY property results in org.hibernate.TransientObjectException after merge

Rahul Devgan (JIRA) noreply at atlassian.com
Sun Nov 14 19:33:13 EST 2010


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2097?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=39104#action_39104 ] 

Rahul Devgan commented on HHH-2097:
-----------------------------------

Hi, I am using hibernate entity manager 3.5.6.Final with JPA and I got the same exception using Lazy Fetch. I employed the workaround of CascadeType.ALL for one relationship and the exception went down the object graph to the next one where only Lazy fetching was specified without the cascade option. Is it a must now to specify cascade type with Lazy fetching?

> LAZY property results in org.hibernate.TransientObjectException after merge
> ---------------------------------------------------------------------------
>
>                 Key: HHH-2097
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2097
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.2.0.cr4
>         Environment: Hibernate3.2 cr4 with Annotations cr2 and EntityManager cr2, Oracle10g R2, WindowsXP
>            Reporter: Reto Urfer
>            Priority: Critical
>         Attachments: BugLazyPropertyMerge.zip
>
>
> Entity1 has a property e2 which references Entity2. This property is defined as follows.
>      @ManyToOne(fetch = FetchType.LAZY, optional = false)
>      private Entity2 e2;
> If you have an instance e1 of Entity1 which has not initialized property e2 and you merge e1 to the EntityManager within a transaction, then you get the following exception during commit:
> Exception in thread "main" javax.persistence.RollbackException: Error while commiting the transaction
> 	at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:63)
> 	at com.test.Test.main(Test.java:42)
> Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.test.Entity1.e2 -> com.test.Entity2
> 	at org.hibernate.engine.CascadingAction$9.noCascade(CascadingAction.java:350)
> 	at org.hibernate.engine.Cascade.cascade(Cascade.java:139)
> 	at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:130)
> 	at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:121)
> 	at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
> 	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
> 	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
> 	at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
> 	at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
> 	at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:53)
> 	... 1 more
> I added a small Testproject to reproduce this bug.

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