3 Replies Latest reply on Aug 9, 2012 3:52 AM by srjy9b

    LazyInitializationException thrown when deleting an entity with global_with_modified_flag turned on.

    srjy9b Newbie

      Hi All,

       

      We are using hibernate envers 4.1.5 with hibernate core 4.1.5.

      We have turned on global_with_modified_flag as follows.

       

       

      hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");

      hibernateProperties.setProperty("javax.persistence.validation.mode", "none");

      hibernateProperties.setProperty("org.hibernate.envers.global_with_modified_flag", "true");

       

       

      We have two entities mapped by a ManyToMany relation. When either of the mapped entities is deleted, the audit entry insertion raises a LazyInitializationException.

      This is our stack trace:

       

       

      org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed

                at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:394)

                at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:386)

                at org.hibernate.collection.internal.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:126)

                at org.hibernate.collection.internal.PersistentSet.isEmpty(PersistentSet.java:163)

                at org.hibernate.envers.entities.mapper.relation.AbstractCollectionMapper.isFromNullToEmptyOrFromEmptyToNull(AbstractCollectionMapper.java:158)

                at org.hibernate.envers.entities.mapper.relation.AbstractCollectionMapper.mapModifiedFlagsToMapFromEntity(AbstractCollectionMapper.java:142)

                at org.hibernate.envers.entities.mapper.MultiPropertyMapper.map(MultiPropertyMapper.java:89)

                at org.hibernate.envers.synchronization.work.DelWorkUnit.generateData(DelWorkUnit.java:65)

                at org.hibernate.envers.synchronization.work.AbstractAuditWorkUnit.perform(AbstractAuditWorkUnit.java:74)

                at org.hibernate.envers.synchronization.AuditProcess.executeInSession(AuditProcess.java:116)

                at org.hibernate.envers.synchronization.AuditProcess.doBeforeTransactionCompletion(AuditProcess.java:155)

                at org.hibernate.engine.spi.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:662)

                at org.hibernate.engine.spi.ActionQueue.beforeTransactionCompletion(ActionQueue.java:307)

                at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:611)

                at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:105)

                at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)

       

      During debugging we also noticed that the session is not null and isOpen returns true in the code below:

       

       

      package org.hibernate.collection.internal;

      Class AbstractPersistentCollection {

       

       

      ....

      private boolean isConnectedToSession() {

                          return session!=null &&

                                              session.isOpen() &&

                                              session.getPersistenceContext().containsCollection(this);

      }

      ....

      }

       

       

      And the collectionEntries in the class StatefulPersistenceContext is empty.

       

       

      Has anyone encountered this problem before?

      Any insight into this issue would be appreciated..

      Thanks in advance.