wood burning stoves*
The moose likes Spring and the fly likes usertransaction.begin(); gets java.lang.NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "usertransaction.begin(); gets java.lang.NullPointerException" Watch "usertransaction.begin(); gets java.lang.NullPointerException" New topic
Author

usertransaction.begin(); gets java.lang.NullPointerException

sagar chandgude
Greenhorn

Joined: Nov 09, 2010
Posts: 5
Hi
Our applicationContext.xml
is
---------------------------
<?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.5.xsd">

<bean id="WASTranMgr" class="com.ibm.wsspi.uow.UOWManagerFactory" factory-method="getUOWManager"/>
<bean id="transactionManager"
class="org.springframework.transaction.jta.WebSphereUowTransactionManager">
<property name="uowManager" ref="WASTranMgr"/>
<property name="autodetectUserTransaction" value="false"/>
</bean>

<bean id="sender" class="test.Sender"/>
<property name="txManager" >
<ref bean="transactionManager"/>
</property>

<bean id="receiver" class="test.Receiver"/>

</beans>
---------------------------------
& our code that is having actual call to begin()

---------------------------------
private static JtaTransactionManager txManager;

public JtaTransactionManager getTxManager() {
return txManager;
}

public void setTxManager(JtaTransactionManager txManager) {
this.txManager = txManager;
}
static UserTransaction usertransaction =null;
private static BeanFactory beanFactory =null;
public static void main(String[] args) throws SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException, SystemException, NotSupportedException {
// TODO Auto-generated method stub
beanFactory = new XmlBeanFactory(new ClassPathResource("/test/applicationContext.xml"));
Sender s=(Sender)beanFactory.getBean("sender");


try{
UserTransaction usertransaction = s.getTxManager().getUserTransaction();
}
catch(Exception e){
System.out.println("**EXCEPTION IS ***"+e);
}
usertransaction.begin();

usertransaction.commit();

}
---------------------------------

when we run we get the

Exception in thread "main" java.lang.NullPointerException

---------------------------------
FYI:
Websphere version is 6.1.0.21
RAD version 7.5.4
We have tried with 2.0 as well 2.5
but still facing the Exception
---------------------------------
Any suggetion would be greatly appreciated

Thanks in Advance ***********
---------------------------------
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

What does

<property name="autodetectUserTransaction" value="false"/>

in your TransactionManager bean do?

Looks like it won't automatically give you a UserTransaction. What happens if you set it to "true"

I am not familiar with that property and what it does, which is why I am asking. It just sticks out to me.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
 
subject: usertransaction.begin(); gets java.lang.NullPointerException
 
Similar Threads
Spring And Hibernate (LocalSessionFactoryBean)
HibernateDaoSupport and Transaction
Sychronization problem with hibernate and weblogic 9.2 JTA
Jboss/JTA/spring "No JTA TransactionManager found"
Exception on Save operation with Spring annotation