Well, the thing is that an injected Session is retrieved from the
HibernateSessionManager. This service is a per-thread service, so every
request (has a seperate, new thread and thus) has its own
HibernateSessionManager. This service automatically starts a new
transaction. (see also
https://svn.apache.org/repos/asf/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateSessionManagerImpl.java)
This basically makes sense, because usually what you want is a
transaction per thread and transaction control using the
HibernateSessionManager's control.
It appears that what you want to do manual transaction management.
Wouldn't it be an option to get a HibernateSessionSource injected and
use that service (which is not per-thread, but global) to acquire
sessions? That way, the HibernateSessionManager part will be skipped.
You may be right that TAP5-137 still needs fixing. Apparently, the
HibernateSessionManagerImpl assumes that it's the only one controlling
transactions. I believe that when transactions are manipulated /outside/
of the HibernateSessionManagerImpl, this /may/ cause issues. Maybe a
developer could look at it.
Op 29-11-2010 19:50, Yury Luneff schreef:
Greetings.
I made a simple example playing with hibernate spatial / etc. I have
following event handler on my page (tapestry 5.1.0.5):
public void onClick() {
Stop stop = new Stop();
WKTReader fromText = new WKTReader();
Geometry poly = null;
Transaction tx = null;
try {
logger.debug("hello, world");
tx = session.beginTransaction();
poly = fromText.read("POINT(1 2)");
stop.setPoint((Point) poly);
session.save(stop);
tx.commit();
} catch (Exception e) {
logger.error("exception: " + e.getMessage());
tx.rollback();
} finally {
}
}
Where session is org.hibernate.Session injected as
tapestry-hibernate-core provided.
Every time this event handler is called i receive an exception:
[WARN] TapestryIOCModule.PerthreadManager Error invoking listener
org.apache.tapestry5.internal.hibernate.hibernatesessionmanageri...@1bab2a6:
Transaction not successfully started
org.hibernate.TransactionException: Transaction not successfully started
at
org.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:149)
at
org.apache.tapestry5.internal.hibernate.HibernateSessionManagerImpl.threadDidCleanup(HibernateSessionManagerImpl.java:65)
at
org.apache.tapestry5.ioc.internal.services.PerthreadManagerImpl.cleanup(PerthreadManagerImpl.java:86)
at
org.apache.tapestry5.ioc.internal.RegistryImpl.cleanupThread(RegistryImpl.java:344)
at
org.apache.tapestry5.ioc.internal.RegistryWrapper.cleanupThread(RegistryWrapper.java:36)
at
org.apache.tapestry5.TapestryFilter.doFilter(TapestryFilter.java:133)
at
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at
org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at
org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
at
org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at
org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at
org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
I suppose this is because playing with Session should be performed in
services, but i'm not sure.
What am I doing wrong? Why does HibernateSessionManager say "rollback"
on transaction he doesn't know anything about?
public void threadDidCleanup()
{
transaction.rollback();
session.close();
}
There is a bug in JIRA about that (more or less):
https://issues.apache.org/jira/browse/TAP5-137
The behavior of this example doesn't have anything to do with
hibernate spatial, there is no exceptions inside try-catch produced.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org