Hibernate session within akka threads

642 views
Skip to first unread message

Grégoire Charvet 夏格

unread,
Jul 20, 2012, 4:38:14 AM7/20/12
to akka...@googlegroups.com
Hello guys

I have a problem with hibernate/spring and akka. I have a regular spring application with service/dao layers configured for transaction. Everything works fine, but not with akka.
Because my actors are not spring beans, I manually set the dependancy for the DAO (this works) but I get the following exception when I try to use the hibernate session:

org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
    at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
    at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:700)
...

The faulty line is:
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(persistentClass);
where session factory is a spring bean for hibernate session.

Again, everything works fine as long as I stay in the spring world.
The exception is thrown from a thread created by akka (something like testSystem-akka.actor.default-dispatcher-1). Is there a workaround for that ?
I found that using HibernateTemplate solve this, but I didn't test it extensively. The solution with hibernate session has been used for a long time so I really want to continue using it.

Thanks
Greg

√iktor Ҡlang

unread,
Jul 20, 2012, 5:45:59 AM7/20/12
to akka...@googlegroups.com

Hi,

Guess: it uses ThreadLocals to keep track of the session.

Cheers, V

--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.
Reply all
Reply to author
Forward
0 new messages