Hello
I am using the Generic DAO approach as described here:
http://www.hibernate.org/328.html
I am using JBoss and JTA with Beans Managed Transactions.
I have set the followong properties:
hibernate.current_session_context_class=jta
hibernate.transaction.manager_lookup_class= org.hibernate.transaction.JBossTransactionManagerLookup
hibernate.transaction.factory_class= org.hibernate.transaction.JTATransactionFactory
in my Session Bean I use this code:
Code:
* saves a given bird to the database
* @ejb.interface-method view-type="remote"
*
*/
public void saveBirdType(BirdType type) {
UserTransaction utx = null;
try {
utx = (UserTransaction) new InitialContext()
.lookup("java:comp/UserTransaction");
utx.begin();
DaoFactory factory = new HibernateDaoFactory();
BirdTypeDao dao = factory.getBirdTypeDao();
dao.save(type);
utx.commit();
} catch (Exception ex) {
try {
utx.rollback();
} catch (Exception e) {
log.error("can not rollback transaction" + e.getMessage(), ex);
}
}
}
I use the HibernateUtil class that comes with the
caveatemptor-native-061211
source code.
I use Hibernate 3.1 RC 1 (can not upgrade right now), JBoss 4.0.3, EJB 2.1 and Java 5.
as a database system I use Oracle 10g.
I get this error:
Caused by: org.hibernate.HibernateException: Unable to locate current JTA transaction
at org.hibernate.context.JTASessionContext.currentSession(JTASessionContext.java:61)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:604)
any idea what's wrong here ?
Claus