users@glassfish.java.net

Re: No Persistence provider for EntityManager!!!!

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Fri, 12 Jun 2009 11:57:35 -0700

You build probably moves/copies things around - persistence.xml is expected to
be in the META-INF directory.

Regards,
-marina

Martin Gainty wrote:
> MG>quick example where persistence.xml is located at
> MG>$GLASSFISH/SEAM/seampagination/seampagination-ejb/src/conf/persistence.xml
> MG>contents are
>
> <persistence version="1.0"
> xmlns="http://java.sun.com/xml/ns/persistence"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
> <persistence-unit name="PetCatalogPu" transaction-type="JTA">
> <jta-data-source>jdbc/PETCatalogDB</jta-data-source>
> <properties/>
> </persistence-unit>
> </persistence>
>
> //$GLASSFISH/SEAM/bp-sessionpagination/bp-sessionpagination-ejb/setup.xml
> contents
> <target name="create-resource-local" depends="tools,create-pool-local">
> <echo message="Registering jdbc resource jdbc/PETCatalogDB."/>
> <antcall target="create-jdbc-resource">
> <param name="pool.name" value="PETCatalogPool" />
> <param name="jdbc.resource.name" value="jdbc/PETCatalogDB" />
> </antcall>
> </target>
>
> //$GLASSISH_HOME/bp-sessionpagination/bp-sessionpagination-ejb/setup/CatalogPool.sun-//resource
> contents:
> <?xml version="1.0" encoding="UTF-8"?>
> <resources>
> <jdbc-connection-pool allow-non-component-callers="false"
> connection-validation-method="auto-commit"
> datasource-classname="org.apache.derby.jdbc.ClientDataSource"
> fail-all-connections="false" idle-timeout-in-seconds="300"
> is-connection-validation-required="false"
> is-isolation-level-guaranteed="true" max-pool-size="32"
> max-wait-time-in-millis="60000" name="PETCatalogPool"
> non-transactional-connections="false" pool-resize-quantity="2"
> res-type="javax.sql.DataSource" steady-pool-size="8"
> validation-table-name="TAB_NAME">
> <property name="serverName" value="localhost"/>
> <property name="PortNumber" value="1527"/>
> <property name="DatabaseName" value="pet-catalog"/>
> <property name="User" value="app"/>
> <property name="Password" value="app"/>
> </jdbc-connection-pool>
> </resources>
>
> //code for Catalog Bean
> @Stateless
> public class CatalogFacadeBean implements CatalogFacade {
>
> //this will reference the unit name defined in Persistence.xml as
> PetCatalogPU
> @PersistenceContext(unitName="PetCatalogPu")
> private EntityManager em;
>
> public Item getItem(String itemID){
> //use the Persistence context to locate itemID
> Item item = em.find(Item.class,itemID);
> return item;
> }
> public Category getCategory(String id){
> //use the Persistence context to locate 'id'
> Category category = em.find(Category.class,id);
> return category;
> }
>
> //code for Item (the query needs the jdbc/PETCatalogDB to ref the DB
> Item table)
> @Entity
> @Table(name = "ITEM")
> @NamedQueries( {
> @NamedQuery(name = "Item.findByItemid", query = "SELECT i FROM Item
> i WHERE i.itemid = :itemid"),
> @NamedQuery(name = "Item.findByName", query = "SELECT i FROM Item i
> WHERE i.name = :name")
> })
> public class Item implements Serializable .....
>
> HTH
> Martin Gainty
> ______________________________________________
> Jogi és Bizalmassági kinyilatkoztatás/Verzicht und
> Vertraulichkeitanmerkung/Note de déni et de confidentialité
>
> Ez az üzenet bizalmas. Ha nem ön az akinek szánva volt, akkor kérjük,
> hogy jelentse azt nekünk vissza. Semmiféle továbbítása vagy másolatának
> készítése nem megengedett. Ez az üzenet csak ismeret cserét szolgál és
> semmiféle jogi alkalmazhatósága sincs. Mivel az electronikus üzenetek
> könnyen megváltoztathatóak, ezért minket semmi felelöség nem terhelhet
> ezen üzenet tartalma miatt.
>
> Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene
> Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede
> unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig.
> Diese Nachricht dient lediglich dem Austausch von Informationen und
> entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten
> Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt
> uebernehmen.
>
> Ce message est confidentiel et peut ętre privilégié. Si vous n'ętes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert ŕ l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement ętre sujets ŕ la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.
>
>
>
>
>
>
> > Date: Fri, 12 Jun 2009 10:41:09 -0700
> > From: Marina.Vatkina_at_Sun.COM
> > To: users_at_glassfish.dev.java.net
> > Subject: Re: No Persistence provider for EntityManager!!!!
> >
> > You might want to read the corresponding chapters in the Java EE 5
> Tutorial.
> >
> > I think you are mixing 2 setups - your persistence.xml specifies the
> datasource,
> > i.e. you are running in a environment where you can do a lookup. Is
> it true? If
> > yes, you should be looking up the EntityManagerFactory, not creating
> it yourself.
> >
> > How does the EnterpriseApplication1-war refer to the
> EnterpriseApplication1-ejb?
> > Where is the persistence.xml located?
> >
> > Regards,
> > -marina
> >
> > glassfish_at_javadesktop.org wrote:
> > > Sorry I don't understand. To recap, what I have done is as follows;
> > > [b]1. netbeans project [/b]
> > > I have created a netbeans Enterprise Application that consists of
> the following;
> > > a. EnterpriseApplication1-ejb : Contains an Entity class called
> Products and a DBAO to access a mySQL database
> > > b. EnterpriseApplication1-war : Contains a Web Service that calls
> logic contained in a.)
> > >
> > > In terms of classpath, I have the following setup;
> > > .;%JAVA_HOME%\bin;%JRE_HOME\bin;C:\Program
> Files\Java\jre6\lib\ext\QTJava.zip;C:\Program Files\NetBeans
> 6.5\java2\modules\ext\hibernate;
> > >
> > > [b]2. Persistence.xml [/b]
> > > The persistence.xml file looks as follows;
> > >
> > > <persistence-unit name="productsPU">
> > > <jta-data-source>depotDB</jta-data-source>
> > > <class>org.rich.entities.Products</class>
> > > <exclude-unlisted-classes>true</exclude-unlisted-classes>
> > > <properties/>
> > > </persistence-unit>
> > >
> > > depotDB refers to a data source that accesses a mySQL database.
> When I go under the covers in netbeans, persistence.xml seems to be in
> the right place.
> > >
> > > [b]3. DBAO Products[/b]
> > > In my database access class, I have the following code
> > >
> > > EntityManagerFactory emf =
> Persistence.createEntityManagerFactory("productsPU");
> > >
> > > EntityManager em = emf.createEntityManager();
> > >
> > > [b]4. The Result[/b]
> > > When I run the application, I get the following;
> > >
> > > Caused by: javax.persistence.PersistenceException: No Persistence
> provider for EntityManager named productsPU: The following providers:
> > > oracle.toplink.essentials.PersistenceProvider
> > > oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider
> > > Returned null to createEntityManagerFactory.
> > >
> > >
> > > As I am relatively new to using netbeans, glassfish and the JPA, I
> have absolutely no idea what is going on. Sadly, I've spent about 8
> hours trying to debug to no avail.
> > >
> > > Any pointers would be much appreciated.
> > > [Message sent by forum member 'rwwebb' (rwwebb)]
> > >
> > > http://forums.java.net/jive/thread.jspa?messageID=350865
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> > > For additional commands, e-mail: users-help_at_glassfish.dev.java.net
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> > For additional commands, e-mail: users-help_at_glassfish.dev.java.net
> >
>
> ------------------------------------------------------------------------
> Windows Live™ SkyDrive™: Get 25 GB of free online storage. Get it on
> your BlackBerry or iPhone.
> <http://windowslive.com/online/skydrive?ocid=TXT_TAGLM_WL_SD_25GB_062009>