views:

255

answers:

2

I'm having trouble starting a transaction with Hibernate and MySQL while running in JUnit. I'm getting a HibernateException which states: "No TransactionManagerLookup specified". I believe this error is because I don't have a proper configuration setting for hibernate.transaction.manager_lookup_class.

I see that under the namespace of org.hibernate.transaction there are quite a few different lookup classes that I could use. All of the documentation that I could find on these was very vague. My question is what is the appropriate one for MySQL?

+1  A: 

I do it with Spring and its transaction managers. Works perfectly.

duffymo
I'm a noob with Spring and Hibernate. Could you perhaps provide a simple example?
James
You're best bet is the Spring reference docs.
duffymo
A: 

To fix this I needed to make the following changes.

  1. Changed the hibernate.cfg.xml => hibernate.current_session_context_class from jta to thread.
  2. Changed the transaction manager to org.springframework.orm.hibernate3.HibernateTransactionManager in the bean configuration.

    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref local="sessionFactory" > <property> <bean>

James