-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: OpenSessionInViewFilter - could not register synchronization
PostPosted: Thu Oct 30, 2008 2:56 pm 
Newbie

Joined: Thu Oct 30, 2008 2:16 pm
Posts: 3
Hibernate version: 3.3.1GA

Full stack trace of any exception that occurs:

Root cause:
org.hibernate.TransactionException: could not register synchronization
at org.hibernate.transaction.JTATransaction.registerSynchronization(JTATransaction.java:316)
at org.hibernate.context.ThreadLocalSessionContext.currentSession(ThreadLocalSessionContext.java:105)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:574)
at edu.andrews.its.services.donate.DonationFormAction.execute(DonationFormAction.java:37)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:103)
at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:39)
at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:87)
at edu.andrews.its.security.SecurityFilter.doFilter(SecurityFilter.java:195)
at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:87)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:87)
at edu.andrews.its.webapp.session.SessionFilter.doFilter(SessionFilter.java:132)
at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:87)
at edu.andrews.its.webapp.ui.CachingFilter.doFilter(CachingFilter.java:64)
at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:87)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:187)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:266)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:270)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:678)
at com.caucho.util.ThreadPool$Item.runTasks(ThreadPool.java:721)
at com.caucho.util.ThreadPool$Item.run(ThreadPool.java:643)
at java.lang.Thread.run(Thread.java:636)

Name and version of the database you are using:
MySQL5 - hibernate is set up for the MySQL5 dialect.

Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html (Yes, I've read it...)

Background on the problem:

I've got a webapp where I'd like to use Hibernate with a Session-per-request and Transaction-per-request. I've already gotten the app working where I manually create a transaction for one particular piece of code that does Hibernate access, so I know my Hibernate config and mappings work OK.

I'm running into problems getting a Transaction-per-request going. The app previously had a TransactionFilter set up that would begin() and commit()/rollback() a JTA transaction for each request. Instead of that, I've installed Spring's OpenSessionInViewFilter to create a Hibernate session for each request. I'm running into the above exception when I try to load a page from my app. I know I might need the TransactionFilter as well - not really sure how that part fits in yet, although I did try things with it as well.

From digging around, it looks like the exception happens in org.hibernate.context.ThreadLocalSessionContext.currentSession(). The lines in question:
if (current == null) {
current = buildOrObtainSession();
current.getTransaction().registerSynchronization(buildCleanupSynch());
...

In this situation, buildOrObtainSession() returns a new session that has a new Transaction. The getTransaction() call returns null because the app server's internal per-thread transaction has not yet been begin()'d (which means it has STATUS_NO_TRANSACTION, which means Resin's getTransaction() method returns null).

Other details:

I'm using Resin 3.1.7 for the app server, and Spring 2.5.5 for its LocalSessionFactoryBean and JtaTransactionManager.

My question:

I want to blame Hibernate (of course) for not calling begin() on the transaction when it creates a new session, but it could be Resin's fault, or most likely mine for misconfiguring or misusing these filters.

1. Does anyone have OpenSessionInViewFilter working to enable per-request transactions for Hibernate? Perhaps together with a transaction filter? If so, which order should they be used in?

2. Is this a bug? Any other relevant info I can provide?

Thanks in advance,
-- Elliot


Top
 Profile  
 
 Post subject: One solution
PostPosted: Thu Oct 30, 2008 4:07 pm 
Newbie

Joined: Thu Oct 30, 2008 2:16 pm
Posts: 3
The solution I just found was to change hibernate's setting for current_session_context_class from 'thread' to 'jta', and remove the OpenSessionInViewFilter altogether (using just the TransactionFilter that was already implemented). This seems to work just fine for my needs...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.