Hibernate Cache Lock error - PullRequest
       1

Hibernate Cache Lock error

2 голосов
/ 07 февраля 2012

Доброе утро.У меня проблема с использованием Hibernate 3.0.0, JBoss 5.1.0GA и jdk1.6. Вот журнал ошибок:

10:53:11,841 WARN  [QueryTranslatorImpl] firstResult/maxResults specified with collection fetch; applying in memory!
10:53:11,909 ERROR [ActionQueue] could not release a cache lock
org.hibernate.cache.CacheException: java.lang.IllegalStateException: Transaction TransactionImple < ac, BasicAction: -53e95dff:de00:4f30f3fb:91 status: ActionStatus.COMMITTED > is not in a valid state to be invoking cache operations on.
    at org.hibernate.cache.jbc2.util.CacheHelper.removeAll(CacheHelper.java:380)
    at org.hibernate.cache.jbc2.util.CacheHelper.removeAll(CacheHelper.java:360)
    at org.hibernate.cache.jbc2.access.TransactionalAccessDelegate.evictOrRemoveAll(TransactionalAccessDelegate.java:146)
    at org.hibernate.cache.jbc2.access.TransactionalAccessDelegate.evictAll(TransactionalAccessDelegate.java:142)
    at org.hibernate.cache.jbc2.entity.TransactionalAccess.evictAll(TransactionalAccess.java:102)
    at org.hibernate.impl.SessionFactoryImpl.evictEntity(SessionFactoryImpl.java:870)
    at org.hibernate.action.BulkOperationCleanupAction.evictEntityRegions(BulkOperationCleanupAction.java:153)
    at org.hibernate.action.BulkOperationCleanupAction.afterTransactionCompletion(BulkOperationCleanupAction.java:132)
    at org.hibernate.engine.ActionQueue.afterTransactionCompletion(ActionQueue.java:198)
    at org.hibernate.impl.SessionImpl.afterTransactionCompletion(SessionImpl.java:451)
    at org.hibernate.jdbc.JDBCContext.afterTransactionCompletion(JDBCContext.java:252)
    at org.hibernate.transaction.CacheSynchronization.afterCompletion(CacheSynchronization.java:117)
    at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.afterCompletion(SynchronizationImple.java:123)
    at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.afterCompletion(TwoPhaseCoordinator.java:381)
    at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:99)
    at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
    at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1423)
    at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:137)
    at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75)
    at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:162)
    at org.jboss.seam.transaction.UTTransaction.commit(UTTransaction.java:52)
    at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:613)
    at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:604)
    at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:345)
    at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:245)
    at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:196)
    at com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:175)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:114)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
    at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
    at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
    at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
    at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
    at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
    at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
    at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
    at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
    at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
    at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
    at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.IllegalStateException: Transaction TransactionImple < ac, BasicAction: -53e95dff:de00:4f30f3fb:91 status: ActionStatus.COMMITTED > is not in a valid state to be invoking cache operations on.
    at org.jboss.cache.interceptors.TxInterceptor.registerTransaction(TxInterceptor.java:727)
    at org.jboss.cache.interceptors.TxInterceptor.attachGlobalTransaction(TxInterceptor.java:474)
    at org.jboss.cache.interceptors.TxInterceptor.attachGtxAndPassUpChain(TxInterceptor.java:300)
    at org.jboss.cache.interceptors.TxInterceptor.handleDefault(TxInterceptor.java:283)
    at org.jboss.cache.commands.AbstractVisitor.visitRemoveNodeCommand(AbstractVisitor.java:75)
    at org.jboss.cache.commands.write.RemoveNodeCommand.acceptVisitor(RemoveNodeCommand.java:125)
    at org.jboss.cache.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:116)
    at org.jboss.cache.interceptors.base.CommandInterceptor.handleDefault(CommandInterceptor.java:131)
    at org.jboss.cache.commands.AbstractVisitor.visitRemoveNodeCommand(AbstractVisitor.java:75)
    at org.jboss.cache.commands.write.RemoveNodeCommand.acceptVisitor(RemoveNodeCommand.java:125)
    at org.jboss.cache.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:116)
    at org.jboss.cache.interceptors.InvocationContextInterceptor.handleAll(InvocationContextInterceptor.java:178)
    at org.jboss.cache.interceptors.InvocationContextInterceptor.visitRemoveNodeCommand(InvocationContextInterceptor.java:88)
    at org.jboss.cache.commands.write.RemoveNodeCommand.acceptVisitor(RemoveNodeCommand.java:125)
    at org.jboss.cache.interceptors.InterceptorChain.invoke(InterceptorChain.java:287)
    at org.jboss.cache.invocation.CacheInvocationDelegate.removeNode(CacheInvocationDelegate.java:478)
    at org.jboss.ha.cachemanager.CacheManagerManagedCache.removeNode(CacheManagerManagedCache.java:317)
    at org.hibernat

e.cache.jbc2.util.CacheHelper.removeAll (CacheHelper.Java: 378) ... еще 70

И вот код, который вызывает эту ошибку:

public void query(String query)
{   
    manager.createNativeQuery(query).executeUpdate();
    manager.clear();
    manager.flush();
}

Ошибка отображается каждый раз, когда я делаю запрос вставки / обновления / удаления.Если вам нужна дополнительная информация, пожалуйста, спросите.Заранее спасибо.

Ответы [ 4 ]

2 голосов
/ 21 ноября 2012

Я наконец нашел обходной путь.В отдельном EJB используйте следующий код:

public class MyEJB {

    @PersistenceContext
    private Session             session;

    public final void update(int param) {
        this.session.doWork(new UpdateWork(param));
    }

    private class UpdateWork implements Work {

        private final int param;

        public UpdateWork(int param) {
            this.param = param;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void execute(Connection connection) throws SQLException {
            PreparedStatement statement = connection.prepareStatement(query);
            int updated = statement.executeUpdate();
            statement.setInt(1,param);
            if (updated > 0) {
                // stuff
            }
        }
    }

} 
1 голос
/ 18 июля 2013

Эта ссылка объясняет, что происходит и как избежать этой ошибки:

Влияние собственных SQL-запросов на кэш второго уровня hibernate

1 голос
/ 21 ноября 2012

Это ошибка Hibernate:

https://hibernate.onjira.com/browse/HHH-3818

Обновление вашей версии Hibernate до версии более 3.3.2 должно решить проблему.

1 голос
/ 07 февраля 2012

Похоже, ваша транзакция уже совершена.Возможно, вам следует создать новую транзакцию для выполнения этой операции.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...