Envirement:nb 7.3.1, java 7
1.create new web project
2.check DB connection
3.create new Web Service, add new operation.
4.create jpa
5.add to newWebService.java the code.
-------------------------------------------------------
package ws;
import cu.Customer;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
@WebService(serviceName = "NewWebService")
public class NewWebService {
@PersistenceUnit
EntityManagerFactory emf;
@WebMethod(operationName = "hello")
public String hello(@WebParam(name = "name") String txt) {
return "Hello " + txt + " !";
}
/**
* Web service operation
*/
@WebMethod(operationName = "operation")
public String operation(@WebParam(name = "index") int index) {
Customer c = (Customer) emf.createEntityManager().createNamedQuery("Customer.findAll").getResultList().get(index);
return c.getName();
}
}