persistence@glassfish.java.net

Re: Can't find persistence.xml from web browser

From: David Van Couvering <David.Vancouvering_at_Sun.COM>
Date: Tue, 26 Sep 2006 16:57:20 -0700

*Really* good idea, Marina, but :( no luck. Note that
D:/derby/DerbyCalendar/web/ is where all my jar files are.

Again, it can find Persistence.class, so in general the classloader's
working the way it should. It's just when it tries to load a resource
(vs. a class).

I suspect an applet bug... If I were eager I'd try to produce an
independent test case, where I simply try to load a resource from inside
an applet, but I don't have the bandwidth right now, and it wouldn't
help me anyway, to report a bug in the applet code and wait nine months
to a year to get it fixed. But this does mean JPA can't run in an
applet as far as I can tell...

Is there any way for me to specify a provider using an API instead of
using persistence.xml??

Dump classloader list ...
     codebase=file:/D:/derby/DerbyCalendar/web/,
key=file:/D:/derby/DerbyCalendar/web/,derbycal.jar,gdata-calendar-1.0.jar,gdata-client-1.0.jar,toplink-essentials.jar,derby.jar,
zombie=false, cache=true, refcount=1, info=sun.plugin.ClassLoaderInfo_at_b02928
Done.

Inside findAllProviders
Got class loader as sun.misc.Launcher$AppClassLoader_at_92e78c

[dvc - skipping PrivilegedActionException traces]
javax.persistence.PersistenceException: No Persistence provider for
EntityManager named derbycal
        at
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:91)
        at
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
        at
org.apache.derbyDemo.derbyCalendar.RequestManager$1.run(RequestManager.java:41)
        at java.security.AccessController.doPrivileged(Native Method)
        at
org.apache.derbyDemo.derbyCalendar.RequestManager.<init>(RequestManager.java:38)
        at
org.apache.derbyDemo.derbyCalendar.DerbyCalendarApplet.login(DerbyCalendarApplet.java:97)
        ... 16 more


Marina Vatkina wrote:
> David,
>
> Just a wild guess... From (searched via Google)
> http://java.sun.com/j2se/1.4.2/docs/guide/misc/applet.html it looks like
> there should be no spaces in the jar list. Also, check that they are
> available from the root of your app.
>
> Can you try?
>
> thanks,
> -marina
>
>
> David Van Couvering wrote:
>
>> First of all, thanks everyone for trying to help.
>>
>> All jar files are in the top-level directory for the web app. This is
>> a pure HTML/JavaScript web application, no JSPs or servlets or PHP or...
>>
>> Other jar files in this list, such as the GData jars, are being loaded
>> just fine.
>>
>> I am currently running it directly from the filesystem.
>>
>> <applet
>> code="org.apache.derbyDemo.derbyCalendar.DerbyCalendarApplet.class"
>> width=1 height=1 name="DerbyCalendarApplet"
>> archive="derbycal.jar, gdata-calendar-1.0.jar,
>> gdata-client-1.0.jar, toplink-essentials.jar, derby.jar">
>> </applet>
>>
>> In the Java console, if I print out the classloader list I get
>>
>> codebase=file:/D:/derby/DerbyCalendar/web/,
>> key=file:/D:/derby/DerbyCalendar/web/,derbycal.jar,
>> gdata-calendar-1.0.jar, gdata-client-1.0.jar, toplink-essentials.jar,
>> derby.jar, zombie=false, cache=true, refcount=1,
>> info=sun.plugin.ClassLoaderInfo_at_f0b7f8
>>
>> Thanks,
>>
>> David
>>
>> Lance J. Andersen wrote:
>>
>>> what does your applet configuration look like in your html? that
>>> could be the culprit
>>>
>>> David Van Couvering wrote:
>>>
>>>> Thanks, Mitesh. I am subscribed now. It bounced me the first time
>>>> I sent an email, but it looks like the request went through. I sent
>>>> it a second time once I was subscribed, and I saw my question but
>>>> that was all. Thanks *very* much for forwarding these responses.
>>>>
>>>> I definitely have a provider listed as you specified, and also I
>>>> must have toplink-essentials.jar in my classpath; otherwise how
>>>> would the javax.persistence.Persistence class even be able to run so
>>>> as to throw the exception below, as this class is also in the
>>>> toplink-essentials jar file?
>>>>
>>>> Note that this file is accepted by the Glassfish persistence library
>>>> when running in a unit test. I get a different error saying "no
>>>> suitable driver" when it tries to get a connection, but that's a
>>>> separate problem; it seems to be making it a lot farther in the unit
>>>> test environment.
>>>>
>>>> So, I can only deduce it's not the format of the persistence.xml,
>>>> and it's not the toplink-essentials.jar not being in the classpath.
>>>> So, what else can cause the exception?
>>>>
>>>> I'm including my persistence.xml file below, if that helps. Note I
>>>> use both types of properties, one with the toplink- prefix and one
>>>> without, because I am getting inconsistent information on the
>>>> mailing list and various tutorials/blogs about what the format
>>>> should be. You might want to do a Google scan and fix all the
>>>> tutorials out there that use the old format for persistence.xml.
>>>>
>>>> Thanks,
>>>>
>>>> David
>>>>
>>>> Mitesh Meswani wrote:
>>>>
>>>>> Hi David,
>>>>>
>>>>> Are you subscribed to persistence alias? Did you get these mails?
>>>>>
>>>>> Thanks,
>>>>> Mitesh
>>>>>
>>>>> Tom Ware wrote:
>>>>>
>>>>>> Hi David,
>>>>>>
>>>>>> 'Just to add to what Mitesh has said.
>>>>>> The javax.persistence.Persistence class is trying to find
>>>>>> potential providers where you see your error. Essentially all it
>>>>>> does is look for a resource on the classpath called:
>>>>>> "META-INF/services/javax.persistence.spi.PersistenceProvider".
>>>>>>
>>>>>> The toplink-essentials.jar contains that resource.
>>>>>>
>>>>>> -Tom
>>>>>>
>>>>>> Mitesh Meswani wrote:
>>>>>>
>>>>>>> Hi David,
>>>>>>>
>>>>>>> As the exception indicates Persistence is not able to find a
>>>>>>> provider for persistence unit. Please make sure that
>>>>>>> 1. Your persistence.xml lists a provider
>>>>>>> <provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>
>>>>>>>
>>>>>>> 2. toplink-essentials.jar is available at runtime.
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Mitesh
>>>>>>>
>>>>>>> David Van Couvering wrote:
>>>>>>>
>>>>>>>
>>>>>>>> Hi, all. I am trying to run Java Persistence from within an
>>>>>>>> applet -- yes, from within an applet.
>>>>>>>>
>>>>>>>> This is kind of urgent. If I can't get this to work, I'm going
>>>>>>>> to have to revert to JDBC.
>>>>>>>>
>>>>>>>> The applet is loading derbycal.jar, which contains three Entity
>>>>>>>> classes and META-INF/persistence.xml.
>>>>>>>>
>>>>>>>> When I run unit tests against derbycal standalone, Glassfish JPA
>>>>>>>> is able to find persistence.xml and runs fine (except that it
>>>>>>>> keeps complaining it can't find a suitable driver, but I can
>>>>>>>> work on that).
>>>>>>>>
>>>>>>>> When I run the applet, however, it says
>>>>>>>>
>>>>>>>> javax.persistence.PersistenceException: No Persistence provider
>>>>>>>> for EntityManager named derbycal
>>>>>>>> at
>>>>>>>> javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89)
>>>>>>>>
>>>>>>>> at
>>>>>>>> javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.derbyDemo.derbyCalendar.RequestManager$1.run(RequestManager.java:41)
>>>>>>>>
>>>>>>>> at java.security.AccessController.doPrivileged(Native Method)
>>>>>>>> at
>>>>>>>> org.apache.derbyDemo.derbyCalendar.RequestManager.<init>(RequestManager.java:38)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.derbyDemo.derbyCalendar.DerbyCalendarApplet.login(DerbyCalendarApplet.java:97)
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> In scanning this mailing list, it appears this is a classloading
>>>>>>>> problem.
>>>>>>>>
>>>>>>>> Does anyone know why the loader can't find
>>>>>>>> META-INF/persistence.xml in derbycal.jar when it's loaded within
>>>>>>>> an applet? How would I tell the applet classloader to look
>>>>>>>> somewhere else? I tried putting it directly into the codebase
>>>>>>>> directory for the applet but that didn't work either.
>>>>>>>>
>>>>>>>> Many thanks,
>>>>>>>>
>>>>>>>> David
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>> ------------------------------------------------------------------------
>>>>
>>>>
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <persistence version="1.0"
>>>> xmlns="http://java.sun.com/xml/ns/persistence"
>>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>>> <persistence-unit name="derbycal">
>>>>
>>>> <provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>
>>>>
>>>> <class>org.apache.derbyDemo.derbyCalendar.DerbyCalEvent</class>
>>>> <class>org.apache.derbyDemo.derbyCalendar.AddEventRequest</class>
>>>> <class>org.apache.derbyDemo.derbyCalendar.GCalendarRequest</class>
>>>> <properties>
>>>> <!-- JDBC connection properties -->
>>>> <property name="toplink.jdbc.driver"
>>>> value="org.apache.derby.jdbc.EmbeddedDriver"/>
>>>> <property name="jdbc.driver"
>>>> value="org.apache.derby.jdbc.EmbeddedDriver"/>
>>>> <property name="toplink.jdbc.connection.string"
>>>> value="jdbc:derby:DerbyCalDb;create=true"/>
>>>> <property name="jdbc.connection.string"
>>>> value="jdbc:derby:DerbyCalDb;create=true"/>
>>>> <property name="toplink.jdbc.user" value="davidvc"/>
>>>> <property name="jdbc.user" value="davidvc"/>
>>>> <property name="toplink.jdbc.password" value="secret"/>
>>>> <property name="jdbc.password" value="secret"/>
>>>> <!-- SQL dialect to use -->
>>>> <property name="toplink.platform.class.name"
>>>> value="oracle.toplink.essentials.platform.database.DerbyPlatform"/>
>>>> <property name="toplink.logging.level" value="INFO"/>
>>>> <property name="toplink.ddl-generation"
>>>> value="drop-and-create-tables"/>
>>>> <property name="toplink.ddl-generation.output-mode"
>>>> value="database"/>
>>>> <property name="toplink.no-weaving" value="true"/>
>>>> <property name="no-weaving" value="true"/>
>>>> </properties>
>>>> </persistence-unit>
>>>> </persistence>
>>>>
>>>>