Hibernate AssertionFailure error when creating associations
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2009 04:50 AM
I don't get an AssociationExists error when I try to create an association that already exists. Instead, I get the following hibernate assertion failure:
This is a pretty obscure error and took me a while to work out. Is this expected behaviour? And what's the best way to defensively program against this?
The only solution I've come up with is to get all target or source assocs (whatever makes the most sense depending on content model) and looping through them to check if the specific association already exists. For nodes that have a lot of assocations (particularly assocs that have many to many relationships), this can be a very intensive and slow operation.
Is there an associationExists method somewhere that I can use?
09:38:26,457 ERROR [org.hibernate.AssertionFailure#<init>] an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)org.hibernate.AssertionFailure: null id in org.alfresco.repo.domain.hibernate.NodeAssocImpl entry (don't flush the Session after an exception occurs) at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:55) at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:164) 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.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000) at sun.reflect.GeneratedMethodAccessor488.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.orm.hibernate3.HibernateTemplate$CloseSuppressingInvocationHandler.invoke(HibernateTemplate.java:1202) at $Proxy71.flush(Unknown Source) at org.alfresco.repo.domain.hibernate.DirtySessionMethodInterceptor.flushSession(DirtySessionMethodInterceptor.java:304) at org.alfresco.repo.node.db.hibernate.HibernateNodeDaoServiceImpl$31.doInHibernate(HibernateNodeDaoServiceImpl.java:3080) at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:372) at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:338) at org.alfresco.repo.node.db.hibernate.HibernateNodeDaoServiceImpl.newNodeAssoc(HibernateNodeDaoServiceImpl.java:3097) 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 org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) at org.alfresco.repo.transaction.TransactionalDaoInterceptor.invoke(TransactionalDaoInterceptor.java:68) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.alfresco.repo.domain.hibernate.DirtySessionMethodInterceptor.invoke(DirtySessionMethodInterceptor.java:381) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy2.newNodeAssoc(Unknown Source) at org.alfresco.repo.node.db.DbNodeServiceImpl.createAssociation(DbNodeServiceImpl.java:1551) at sun.reflect.GeneratedMethodAccessor485.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) at org.alfresco.repo.transaction.SingleEntryTransactionResourceInterceptor.invokeInternal(SingleEntryTransactionResourceInterceptor.java:163) at org.alfresco.repo.transaction.SingleEntryTransactionResourceInterceptor.invoke(SingleEntryTransactionResourceInterceptor.java:138) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy7.createAssociation(Unknown Source) at sun.reflect.GeneratedMethodAccessor485.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) at org.alfresco.repo.tenant.MultiTNodeServiceInterceptor.invoke(MultiTNodeServiceInterceptor.java:110) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy7.createAssociation(Unknown Source) at sun.reflect.GeneratedMethodAccessor485.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.alfresco.repo.service.StoreRedirectorProxyFactory$RedirectorInvocationHandler.invoke(StoreRedirectorProxyFactory.java:221) at $Proxy8.createAssociation(Unknown Source) at sun.reflect.GeneratedMethodAccessor485.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) at org.alfresco.repo.node.MLPropertyInterceptor.invoke(MLPropertyInterceptor.java:306) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.alfresco.repo.node.MLPropertyInterceptor.invoke(MLPropertyInterceptor.java:306) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.alfresco.repo.node.NodeRefPropertyMethodInterceptor.invoke(NodeRefPropertyMethodInterceptor.java:274) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.alfresco.repo.node.NodeRefPropertyMethodInterceptor.invoke(NodeRefPropertyMethodInterceptor.java:274) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy7.createAssociation(Unknown Source) at com.ixxus.alfresco.webscripts.PushContentToEnvironmentWebScript.doExecute(PushContentToEnvironmentWebScript.java:193) at com.ixxus.alfresco.webscripts.StreamingWebScriptTemplate.execute(StreamingWebScriptTemplate.java:26) at org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:328) at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:322) at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:229) at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:377) at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:399) at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:282) at org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:294) at org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:172) at org.alfresco.web.scripts.servlet.WebScriptServlet.service(WebScriptServlet.java:122) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859) at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:574) at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1527) at java.lang.Thread.run(Unknown Source)09:38:26,566 ERROR [org.hibernate.AssertionFailure#<init>] an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)org.hibernate.AssertionFailure: null id in org.alfresco.repo.domain.hibernate.NodeAssocImpl entry (don't flush the Session after an exception occurs) at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:55) at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:164) 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.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.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:578) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:662) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:632) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:314) at org.alfresco.util.transaction.SpringAwareUserTransaction.commit(SpringAwareUserTransaction.java:466) at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:336) at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:229) at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:377) at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:399) at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:282) at org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:294) at org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:172) at org.alfresco.web.scripts.servlet.WebScriptServlet.service(WebScriptServlet.java:122) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859) at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:574) at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1527) at java.lang.Thread.run(Unknown Source)
This is a pretty obscure error and took me a while to work out. Is this expected behaviour? And what's the best way to defensively program against this?
The only solution I've come up with is to get all target or source assocs (whatever makes the most sense depending on content model) and looping through them to check if the specific association already exists. For nodes that have a lot of assocations (particularly assocs that have many to many relationships), this can be a very intensive and slow operation.
Is there an associationExists method somewhere that I can use?
Labels:
- Labels:
-
Archive
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2009 06:48 AM
Here's the code I'm using btw:
I don't understand why the final catch doesn't seem to actually catch the hibernate exception.
Any suggestions?
try { log.debug("nPushing " + node); nodeService.createAssociation(env, node, CustomContentModel.ASSOC_UPDATED_CONTENT); } catch (AssociationExistsException assocEx){ log.debug(" – Association already exists"); } catch(Exception ex) { log.debug(" – FAILED"); }
I don't understand why the final catch doesn't seem to actually catch the hibernate exception.
Any suggestions?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2010 12:10 PM
I ran the following unit test on 3.1.2, just to make sure that the AssociationExistsException is still being thrown as appropriate
org.alfresco.repo.node.BaseNodeServiceTest.testDuplicateAssociationDetection()
This unit test is run during every Alfresco build, so we simply wouldn't release a build without this functionality working.
Your stack trace would suggest that the flush() that's used by createAssociation() is flushing out another problem that's causing Hibernate to complain. Perhaps there was a previous error in the same transaction?
If you are still experiencing the problem, please provide a simple test case that reproduces the problem.
Thanks
Dave
org.alfresco.repo.node.BaseNodeServiceTest.testDuplicateAssociationDetection()
This unit test is run during every Alfresco build, so we simply wouldn't release a build without this functionality working.
Your stack trace would suggest that the flush() that's used by createAssociation() is flushing out another problem that's causing Hibernate to complain. Perhaps there was a previous error in the same transaction?
If you are still experiencing the problem, please provide a simple test case that reproduces the problem.
Thanks
Dave
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2010 08:52 AM
Hi,
With Hibernate, you can't catch a DAO-level exception and continue as normal; the Hibernate Session must be considered to be corrupted i.e. you need to handle the exception outside of your transaction and redo the transaction with an alternative approach. This is a function of Hibernate (as you can see from the flush exception you get) and will be avoidable when we run without Hibernate.
Regards
With Hibernate, you can't catch a DAO-level exception and continue as normal; the Hibernate Session must be considered to be corrupted i.e. you need to handle the exception outside of your transaction and redo the transaction with an alternative approach. This is a function of Hibernate (as you can see from the flush exception you get) and will be avoidable when we run without Hibernate.
Regards
