UserTransaction reports nullpointer exception

C

Chen

i have java code below

///////////////////////////////////////////////////////////
@WebService()
public class WebJpa {
@PersistenceUnit
//The emf corresponding to
private EntityManagerFactory emf;

@Resource
private UserTransaction utx;


/**
* Web service operation
*/
@WebMethod(operationName = "insert")
public void insert(String id, String firstname, String lastname) {
try{
utx.begin();
EntityManager em=emf.createEntityManager();
Person p=new Person(id, firstname, lastname);

em.persist(p);
em.close();
utx.commit();
}catch(Exception e){
e.printStackTrace();
}
}

}
////////////////////////////////////////////////

it always reports null pointer exception at utx.begin(). Can anybody
tell me why? i am using glassfish v2 as the container.

Thanks a lot.

Chen
 
S

Stanimir Stamenkov

Wed, 8 Oct 2008 02:44:29 -0700 (PDT), /Chen/:
@WebService()
public class WebJpa {
@PersistenceUnit
//The emf corresponding to
private EntityManagerFactory emf;

@Resource
private UserTransaction utx;
[...]

it always reports null pointer exception at utx.begin(). Can anybody
tell me why? i am using glassfish v2 as the container.

As far as I know your bean should be declared as:

@javax.ejb.TransactionManagement(javax.ejb.TransactionManagementType.BEAN)
public class WebJpa ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top