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
///////////////////////////////////////////////////////////
@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