Hello Guys,
I am trying to do UserTransaction using Hibernate. Whenever I try to do some transaction, I get following exception. Any idea how to solve this problem:-
Here is the exception :-
Quote:
org.hibernate.HibernateException: createCriteria is not valid without active transaction
My Codes are like this :-
Code:
HibernateConfig.xml
<hibernate-configuration>
<session-factory name="com.rci.services.offer.SessionFactory">
<property name="hibernate.connection.datasource">jdbc/OfferDataSource</property>
<property name="hibernate.current_session_context_class">jta</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<!---XA transaction--->
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WeblogicTransactionManagerLookup</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property>
UserTransaction tx = null;
try{
tx = (UserTransaction)new InitialContext().lookup("java:comp/UserTransaction");
tx.begin();
HibernateConfig objHbCfg = null;
objHbCfg = OfferHibernateUtil.getHibernateConfig(OfferServiceConstant.OFFER_DOMAIN);
Session session1 = objHbCfg.currentSession(HibernateConfigType.OFFER);
OfferPo offerPo= new OfferPo();
Long offerId= new Long(2577);
Criteria crit = session1.createCriteria(OfferPo.class);
crit.add(Restrictions.eq("offerId", offerId));
offerPo = (OfferPo) crit.list().get(0);
String processId = offerPo.getOfferProcessId();
Can anybody plz tell me where am I wrong?
Regards,
Ranen