File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes Unable to retrieve EntityManagerFactory for unitName FibServicePU Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "Unable to retrieve EntityManagerFactory for unitName FibServicePU" Watch "Unable to retrieve EntityManagerFactory for unitName FibServicePU" New topic
Author

Unable to retrieve EntityManagerFactory for unitName FibServicePU

Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 758
I am trying the example in Java Web Service up and running book on p.256.
I have an rc.jar with ch06/ejb/Fib.class, ch06/ejb/FibEJB, ch06/ejb/FibNum
I also have a fib.ear with rc.jar and META-INF/persistence.xml
I put the fib.ear in glassfish 's domains/domain1/autodeploy/ and deploy it.
I create the client side from the WSDL generated from the deployment.
However, when I run the client, I got this on the client window:
javax.xml.ws.soap.SOAPFaultException: javax.ejb.EJBException

The glassfish window shows Unable to retrieve EntityManagerFactory for unitName FibServicePU.

Please help.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1675
    
  25

Hi Himai,

If I read it well you have put your persistence.xml in the META-INF directory of your EAR-file instead of the META-INF directory of your EJB-JAR file (rc.jar).

Regards,
Frits
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 758
Yes, my fib.ear has rc.jar and META-INF/persistence.xml like this:
fib.ear
-- rc.jar
-- META-INF
--- persistence.xml


I checked online and a web site suggests putting the rc.jar inside lib folder to make this:
fib.ear
-- lib
--- rc.jar

--META-INF
--- persistence.xml

I will try to put create a lib folder and create the fib.ear again tonight and see if it works.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1675
    
  25

What I meant is to put the persistence.xml inside the META-INF dir of the rc.jar (and leave the META-INF dir of the ear empty)


Regards,
Frits
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 758
Frits,
I tried your suggestion. But I got this error message:
org.eclipse.persistence.exceptions.ConversionExcepiton.
THe object [oracle.toplink.essentials.platform.database.DerbyPlatform] of class [class java.lang.String] cannot be
converted to [class java.lang.Class]

I cannot deploy my fib.ear

Anyone suggestion?
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1675
    
  25

How does your persistence.xml look like?

Regards,
Frits
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 758
I commented out the DerbyPlatform, it works partially.


You can refer to my other post , where I ran into other problems.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1675
    
  25

When I read the story from Oracle Glassfish persistence.xml, it looks a bit different from yours. Maybe you can try the given property from their example (I guess you are already using the <jta-data-source>jdbc/__default</jta-data-source>, right?)

Regards,
Frits
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 758
Hi, Frit,
This is the persistence.xml, that I modified from Martin Kalin's book:


I also modified the FibEJB.java

But I got a MarshalException. It seems like the next object cannot be marshalled.

Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1675
    
  25

Hi Himai,

I had a closer look at it and I found out that there is a coding error. What you select from the database is a List of FibNum's, so this code in the book is wrong:

This is the correct code:

This will show up when the method is call from the client:

INFO: FibNum: 1 : 1
INFO: FibNum: 2 : 1
INFO: FibNum: 3 : 2
INFO: FibNum: 4 : 3
INFO: FibNum: 5 : 5
INFO: FibNum: 6 : 8
INFO: FibNum: 7 : 13

You need to adjust the client as well.

Regards,
Frits
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 758
Thanks, Frit. Let me try it again later.
By the way, "select f from FibNum f", why we need "f" at the end?
Usually, the syntax is something like this "select name from PeopleTable".
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1675
    
  25

By the way, "select f from FibNum f", why we need "f" at the end?

That is just EJB QL syntax (see JSR-317 JPA 2.0)
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 758
Hi, Frit. Thanks a lot. We finally make the code work.
Here is what we need to change:


I need to comment out the property name="toplink.platform.class.name"... in order to make it run.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1675
    
  25

Yes, the difference between the solutions is:

and

The em.createQuery() works as a "SELECT * FROM FibNum" and returns a list of FibNums
The em.createNativeQuery() selects just one column (named "f") and returns a list of Integers

The database has two columns (because of the @Entity): N and F, both Integers.

Regards,
Frits
 
jQuery in Action, 2nd edition
 
subject: Unable to retrieve EntityManagerFactory for unitName FibServicePU