Getting “Transaction not successfully started”
Getting “Transaction not successfully started”
I got this WARN everytime I inserted / updated to DB. But my data is still saved, though. Still, I want to get rid of this from my log file.
Below is my log file:
[WARN] TapestryIOCModule.PerthreadManager Error invoking listener org.apache.tapestry5.internal.hibernate.HibernateSessionManagerImpl@41c045: Transaction not successfully started org.hibernate.TransactionException: Transaction not successfully started at org.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:179) at org.apache.tapestry5.internal.hibernate.HibernateSessionManagerImpl.threadDidCleanup(HibernateSessionManagerImpl.java:65)
at org.apache.tapestry5.ioc.internal.services.PerthreadManagerImpl.cleanup(PerthreadManagerImpl.java:128)
at org.apache.tapestry5.ioc.internal.RegistryImpl.cleanupThread(RegistryImpl.java:445)
at org.apache.tapestry5.ioc.internal.RegistryWrapper.cleanupThread(RegistryWrapper.java:38)
at org.apache.tapestry5.TapestryFilter.doFilter(TapestryFilter.java:178)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399)
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:766)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
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.content(HttpConnection.java:945)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
And this is my service impl:
private HibernateSessionManager sessionManager;
public HibernateSessionManager getSessionManager() {
return sessionManager;
}
public void setSessionManager(HibernateSessionManager sessionManager) {
this.sessionManager = sessionManager;
}
@Inject
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public Session getHibernateSession() {
if (getSessionManager() != null)
return getSessionManager().getSession();
else
return sessionFactory.getCurrentSession();
}
@SuppressWarnings("rawtypes")
public Criteria createCriteria(Class clazz, Criterion... criterion) {
Session session = getHibernateSession();
if (!session.getTransaction().isActive())
session.beginTransaction();
Criteria crit = session.createCriteria(clazz);
for (Criterion c : criterion)
crit.add(c);
return crit;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public <T, ID extends Serializable> T get(ID id, boolean lock, Class clazz) {
if (id == null)
return null;
T entity;
Session session = getHibernateSession();
if (!session.getTransaction().isActive())
session.beginTransaction();
if (lock)
entity = (T) session.load(clazz, id);
else
entity = (T) session.get(clazz, id);
return entity;
}
@SuppressWarnings("rawtypes")
public <T extends Serializable> List<T> findAll(Class clazz) {
return findByCriteria(clazz);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public <T extends Serializable> List<T> findByCriteria(Class clazz, Criterion... criterion) {
Session session = getHibernateSession();
Criteria crit = session.createCriteria(clazz);
for (Criterion c : criterion)
crit.add(c);
return crit.list();
}
public <T extends Serializable> T create(T entity) {
Transaction tx = getHibernateSession().beginTransaction();
getHibernateSession().saveOrUpdate(entity);
tx.commit();
return entity;
}
public <T extends Serializable> T update(T entity) {
Transaction tx = getHibernateSession().beginTransaction();
getHibernateSession().saveOrUpdate(entity);
tx.commit();
return entity;
}
public <T extends Serializable> void delete(T entity) {
Transaction tx = getHibernateSession().beginTransaction();
getHibernateSession().delete(entity);
tx.commit();
}
public <T extends Serializable> void createOrUpdate(T entity) {
Transaction tx = getHibernateSession().beginTransaction();
getHibernateSession().saveOrUpdate(entity);
tx.commit();
}
public <T extends Serializable> T merge(T entity) {
Transaction tx = getHibernateSession().beginTransaction();
getHibernateSession().merge(entity);
tx.commit();
return entity;
}
// USER
@Override
public User createOrUpdateUser(User user) {
if (user.getId() == null || user.getId() == 0) {
String encodePass = PasswordUtils.EncodePassword(user.getName(), user.getPassword());
user.setPassword(encodePass);
}
if (user.getId() == null)
return create(user);
else
return update(user);
}
@Override
public User getUserByID(Integer id) {
return get(id, false, User.class);
}
I don't know if this can affect my application performance. Another answer from Stack Overflow with the same issue didn't help solve mine. I wonder if my case is different.
1 Answer
1
Have you tried using the @CommitAfter annotation instead of starting and committing transations explicitly in code?
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.