2012-09-28 25 views
1

我已經實現DAO的基於HibernateDAOFactory類Link,有一種方法部署在JBoss使用的getCurrentSession

protected Session getCurrentSession() { 
    return HibernateUtil.getSessionFactory().getCurrentSession(); 
} 

爲了實現我已經如在下面描述所作的變化的hibernate.cfg.xml相同文章Here 1 HERE 2

<property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property><br/> 
    <property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property> 
    <property name="hibernate.current_session_context_class">thread</property> 

儘管JBoss上我碰到下面的錯誤進行部署

org.hibernate.TransactionException: could not register synchronization 

我甚至設置屬性

<property name="hibernate.current_session_context_class">jta</property> 

,但我得到了下面的錯誤。

Caused by: org.hibernate.HibernateException: Unable to locate current JTA transaction 

at org.hibernate.context.JTASessionContext.currentSession(JTASessionContext.java:88) 

at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:574) 

我是否缺少這裏的東西? 我的版本的JBoss 4.2.3是和休眠的版本是3.3.1,並使用Java 7

+0

如何定義數據源? – user1516873

+0

你如何管理交易?你有春天還是手動做? – user1516873

+0

public static Session getCurrentSession() Session currentSession = getSessionFactory()。getCurrentSession();如果(!currentSession.getTransaction()。isActive()) { currentSession.getTransaction()。begin(); } return currentSession; \t} – Sandeep

回答

0

那麼基於線程會話管理,我從我的hibernate.cfg.xml取出transaction.factory_classmanager_lookup_class性能和它的工作就像一個魅力。
但是對於基於jta的會話管理,我仍然收到相同的錯誤。