persistence@glassfish.java.net

Re: persistence.xml not picked up in webapp

From: Pierre Delisle <Pierre.Delisle_at_Sun.COM>
Date: Fri, 13 Jan 2006 17:16:18 -0800

Well, it ended up being a pilot error.

Small typo in my webapp dir structure:
   WEB-INF/classes/META_INF/persistence.xml,
       instead of
   WEB-INF/classes/META-INF/persistence.xml.

Apologies for the noise, and thanks to Ludo and Mitesh who
were kind enough to double check my setup.

    -- Pierre

My .02 on what would have helped:

When persistence does not find "pu1", it would be awesome if it could
tell me:
   - the list of PersistenceUnits it knows of
   - if none are known:
         - where it tried to load persistence.xml

If that information had been provided, I think I'd have been able
to recover from my pilot error quite easily.
There's no such thing as error messages that are too verbose in my
book, and a developer will be really thankful when he's the victim
of such errors.

Pierre Delisle wrote:

> All persistence jars are added in
> <tomcat.home>/common/lib.
>
> After talking to Ludo, I wonder if this could be something
> related to class loading.
>
> Anyone knowing the specifics of how persistence.xml is being
> loaded? (I know, I know, I should check the code myself, but in case
> someone has that information handy :-))
>
> -- Pierre
>
> Mitesh Meswani wrote:
>
>
>>Hi Pierre,
>>
>>Where have you put the persistence jars (javaee.jar,
>>toplink-essentials.jar, asm.jar, antlr.jar)
>>
>>Thanks,
>>Mitesh
>>
>>Pierre Delisle wrote:
>>
>>
>>>I have been successful in running the persistence example at
>>>https://glassfish.dev.java.net/javaee5/persistence/persistence-example.html
>>>
>>>on Java SE using the no.weaving property (so I would not have to specify
>>>-javaagent).
>>>
>>>Now, I would like to run a very similar example (i.e. uses Persistence
>>>with
>>>Java SE), but within a web application in a container that is not
>>>Java EE 5 compliant (e.g. Tomcat 5.5.x).
>>>
>>>I have persistence.xml located in WEB-INF/classes/META-INF of my webapp
>>>that looks like this:
>>>
>>> <persistence xmlns="http://java.sun.com/xml/ns/persistence">
>>> <persistence-unit name="pu1">
>>>
>>><provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>
>>>
>>> <class>crud.models.Product</class>
>>> <properties>
>>> <property name="jdbc.driver"
>>>value="org.gjt.mm.mysql.Driver"/>
>>> <property name="jdbc.connection.string"
>>>value="jdbc:mysql://localhost:3306/test?autoReconnect=true"/>
>>> <property name="jdbc.user" value=""/>
>>> <property name="jdbc.password" value=""/>
>>> <property name="toplink.logging.level" value="INFO"/>
>>> <property name="no.weaving" value="true"/>
>>> </properties>
>>> </persistence-unit>
>>> </persistence>
>>>
>>>
>>>When I run the webapp under Tomcat 5.5.7, it fails when the
>>>code tries to create the EntityManagerFactory:
>>>
>>> javax.persistence.PersistenceException: No Persistence provider for
>>>EntityManager named pu1
>>>
>>>javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:67)
>>>
>>>
>>>Looks like the 'persistence.xml' descriptor is not being picked up.
>>>
>>>So... Where exactly is the 'persistence.xml' file supposed to be located
>>>in my webapp so it can be picked up by Java Persistence?
>>>
>>>Thanks,
>>>
>>> -- Pierre
>>>
>>
>>
>