File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sychronization problem with hibernate and weblogic 9.2 JTA

 
Ramakrishna Gundraju
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am trying to use hibernate 3 and weblogic 9.2 JTA with spring 2.0 configurations.But I am getting follwing exception

"Could not register synchronization with JTA TransactionManager"

Here are the full details:

My Exception
----------------

log4j:WARN No appenders could be found for logger (org.springframework.context.support.FileSystemXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
I am inside TestDAO DAO calling SaveorUpdate method in HibernateTemplate and returning the List
Exception in thread "main" org.springframework.dao.DataAccessResourceFailureException: Could not register synchronization with JTA TransactionManager; nested exception is javax.transaction.SystemException: You may enlist a resource only on a server
Caused by: javax.transaction.SystemException: You may enlist a resource only on a server
at weblogic.transaction.internal.TransactionImpl.registerSynchronization(TransactionImpl.java:514)
at org.springframework.orm.hibernate3.SessionFactoryUtils.registerJtaSynchronization(SessionFactoryUtils.java:460)
at org.springframework.orm.hibernate3.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:344)
at org.springframework.orm.hibernate3.SessionFactoryUtils.getSession(SessionFactoryUtils.java:233)
at org.springframework.orm.hibernate3.HibernateTemplate.getSession(HibernateTemplate.java:425)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:361)
at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:686)
at com.fedex.hibernate.TestDAO.saveOrUpdate(TestDAO.java:22)
at com.fedex.hibernate.SpringHBClient.main(SpringHBClient.java:67)


My applicationContext.xml
-------------------------
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">

<property name="jndiName" value="ramsxads2" />


</bean>
<bean id="userTransaction"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="cache" value="false" />
<property name="proxyInterface"
value="javax.transaction.UserTransaction" />
<property name="jndiName"
value="javax.transaction.UserTransaction" />
</bean>

<bean id="txManager"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="proxyInterface"
value="javax.transaction.TransactionManager" />
<property name="jndiName"
value="javax.transaction.TransactionManager" />
</bean>

<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransaction" ref="userTransaction" />
<property name="transactionManager" ref="txManager" />
</bean>

<bean id="sessionFactory1"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />


<property name="mappingResources">
<list>
<value>com/fedex/hibernate/Event.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WeblogicTransactionManagerLookup</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>
<prop key="hibernate.current_session_context_class">jta</prop>
<prop key="hibernate.connection.autocommit">false</prop>
<prop key="hibernate.connection.pool_size">0</prop>


</props>
</property>
</bean>

<bean id="testDAO" class="com.fedex.hibernate.TestDAO">
<property name="sessionFactory" ref="sessionFactory1" />
</bean>

</beans>

My client Program SpringHBClient
--------------------------------


import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import javax.transaction.NotSupportedException;
import javax.transaction.SystemException;
import javax.transaction.UserTransaction;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.context.ApplicationContext;

public class SpringHBClient {

public static void main(String args[]){
Event theEvent = new Event();
theEvent.setId(33333L);
theEvent.setTitle("Success");
Context ctx = null;
UserTransaction ut=null;


Hashtable<String, String> ht = new Hashtable<String, String>();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL, "t3://localhost:7001");

try {
ctx = new InitialContext(ht);
ut = (UserTransaction)
ctx.lookup("javax.transaction.UserTransaction");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

ApplicationContext context=SampleContext.getContext();
try {
ut.begin();
} catch (NotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

TestDAO testDAO=(TestDAO)context.getBean("testDAO");
testDAO.saveOrUpdate(theEvent);
try {
ut.rollback();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}
My spring hibernateTemplate class TestDAO.java
----------------------------------------------
public class TestDAO extends HibernateDaoSupport {


protected void saveOrUpdate(Object obj)
{
logger.debug("Enter the save(object) in the TestDAO Class");
System.out.println("I am inside TestDAO DAO calling SaveorUpdate method in HibernateTemplate and returning the List");

getHibernateTemplate().saveOrUpdate(obj);

logger.debug("Exit from the save(object) int the TestDAO Class");
}

}
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic