Skip to main content

Does WebServices woks with persistence?

10 replies [Last post]
samflores
Offline
Joined: 2006-03-12

Hi,

I wrote the following class:

<br />
@Stateless<br />
@WebService<br />
public class CustomerManager {<br />
    @PersistenceContext EntityManager em;<br />
    ...<br />
    @WebMethod<br />
    public Customer createCustomer( BigInteger code, String name) {<br />
        Customer customer = new Customer( code, name );<br />
        em.persist( customer );<br />
        return customer;<br />
    }<br />
    @WebMethod<br />
    public Collection getCustomerList() {<br />
        String ejbQL = "SELECT c FROM Customer";<br />
        return em.createQuery( ejbQL ).getResultList();<br />
    }<br />
    ...<br />
}<br />

The Customer class is an entity packaged in a jar inside the lib folder of the application.

I could compile, package and deploy the application in glassfish b42 without problems, but when I try use the Tester feature from Admin Console the createCustomer method shows me the SOAP request and response, but the entity isn't persisted in the database. If I call the getCustomerList method I get the SOAP response with an empty list.

For test purpose I created a Servlet Web Application with the CustomerManager injeted with @EJB and called the both method and the persistence worked just fine...

After that the calls to getCustomerList using the Web Service Test give the customers inserted with the servlet inside the SOAP message, but the createCustomer still doesn't persist the created object.

If someone want to see the webapp, it's available in http://flores.ath.cx:8080/webapp/index.html (createCustomer call) and http://flores.ath.cx:8080/webapp/list.html (getCustomerList call). The WSDL for the service can be viewed at http://flores.ath.cx:8080/CustomerManagerImplementationService/CustomerM...

Can someone show me what I'm doing wrong?? :(

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
samflores
Offline
Joined: 2006-03-12

Let me see I understood what Sahoo said:

My code doesn't work 'couse the primary key of my entity is a BigInteger and WebService is treating BigIntegers as null and the primary key can't be null, right?

My ejbQL is equals to yours. That was an typo... I coudn't put my hands in the code when I was posting that. So I have to remenber it (I was at work:))

Third the think about the persistence in an external jar was solved in b42 dated 25-mar.

samflores
Offline
Joined: 2006-03-12

Hello,
I inserted a [b]System.out.println( code )[/b] in the [b]createCustomer[/b] method and searched it in server log. Really it's null. :(
So I tested switching the type of the [b]code[/b] field in the [b]Customer[/b] entity from [b]BigInteger[/b] to [b]Long[/b]. Now everything works fine, but my application needs the [b]code[/b] field be a [b]BigInteger[/b].
Should I fill a bug report about that issue?

ss141213
Offline
Joined: 2005-03-30

yes, please file a bug (category webservice) with your test case.

Sahoo

vijaysr
Offline
Joined: 2003-06-11

Posting this so that people searching the forum will know what action was taken for this issue.

Issue 508 was opened for this problem in the issue tracker - thay issue has been updated with all details

samflores
Offline
Joined: 2006-03-12

thanks, vijaysr.

Samuel Flores

ss141213
Offline
Joined: 2005-03-30

Hi,

I just tried writing an app along the lines of yours and it [b]worked[/b]. My CustomerManager class was exactly what you wrote. My Customer class looks like this:
@Entity public class Customer implements java.io.Serializable {
BigInteger bigInteger;
[b]@Id String name;[/b]
public Customer(){}
public Customer(BigInteger bi, String name) {
this.bigInteger = bi;
this.name = name;
}
}
See here that name is the ID, not the code.

My persistence.xml looks like this:

[i]I packaged all of them into a jar file called ejb.jar and deployed. So my ejb.jar looks like this:[/i]

META-INF/persistence.xml
pkg/Customer.class
pkg/CustomerManager.class

I deployed using [i]asadmin deploy --createtables ejb.jar[/i]
This also created tables for me.

Now I could test using the Tester app in the admin console.

During testing I also saw that, every time, [b]bigInteger is null in the create method[/b]. I don't know why. Have not debugged that yet.

Secondly, your EJBQL did not compile. I had to write
"SELECT c FROM Customer c".

[u]What did not work for me:[/u]
Deploying as a standalone ejb jar worked. But I am seeing some issues deployment when I tried to organise the app as an ear file as follows:

app.ear
ejb.jar (Contains CustomerManager.class)
lib/entities.jar (Contains Customer.class & persistence.xml)

This gave me the following error:
CLI171 Command deploy failed : Deploying application in domain failed; Fatal Error from EJB Compiler -- /space/ss141213/WS/gf/publish/glassfish/domains/domain1/generated/xml/j2ee-apps/forum_14277/ejb_jar/META-INF/wsdl/CustomerManagerService.wsdl (No such file or directory)

It could be that I have not refreshed my workspace and hence could be using a slightly older build. But, my persistence module is up-to-date.

I will follow up this failure later on.

Hope this helps,
Sahoo

vijaysr
Offline
Joined: 2003-06-11

Thanks Sanjeeb.

The deployment failure in the case of EAR is probably because of older workspace. I checked in the fix for taking into account dependent classes in library JARs late last week.

I will look into why BigInteger is always null

ludo
Offline
Joined: 2003-06-10

For EJBQL error reporting in server log, I filed:
https://glassfish.dev.java.net/issues/show_bug.cgi?id=503

ludo
Offline
Joined: 2003-06-10

I also filed another P2 bug regarding file locking at multiple deploy times for the WSDL file:

https://glassfish.dev.java.net/issues/show_bug.cgi?id=504

vijaysr
Offline
Joined: 2003-06-11

Is it possible for you to see if the createCustomer call comes to the @WebMethod createCustomer with proper arguments (a System.out.println in this method will go the server.log) - if the request comes in properly to the @WebMethod but still the persistence does not happen, then probably something else is wrong. Please let us know while I ask someone from the persistence team to look into this