RE: persistence unit can not be found during test
Thanks for the reply. I think now I figure out what goes wrong. The exception reported by the surefire is a red herring. It is indeed related to the dependency matrix issue. Orginally my hibernate entity-manager is 3.4.0 and hibernate-annotations is 3.2.1 (I can not remember exactly its version). That would not work due to compatibility issue. Hibernate page has a compatibility matrix at https://www.hibernate.org/6.html#A3. So I change to use the following configuration that solves part of problems. org.hibernate hibernate-annotations 3.3.1.GA org.hibernate hibernate-entitymanager 3.3.2.GA Also, it requires to add pkg.pathto.ClassName in persistence.xml. org.hibernate.ejb.HibernatePersistence pkg.pathto.ClassName ... So that it will scan the class which would prevent error like Caused by: java.lang.IllegalArgumentException: Unknown entity: pkg.pathto.ClassName Thanks all your help. I really appreciate it. --- On Wed, 12/8/09, Martin Gainty wrote: > From: Martin Gainty > Subject: RE: persistence unit can not be found during test > To: users@maven.apache.org > Date: Wednesday, 12 August, 2009, 8:33 PM > > why not use > oracle-toplink such as this example from > /src/conf/persistence.xml > > > transaction-type="JTA" > > oracle.toplink.essentials.PersistenceProvider > > > > jdbc/someDefinableName > > someORMap.xml > entities/Jar.jar > > ejbinaction.persistence.Category > ejbinaction.persistence.Bid > > name="toplink.ddl-generation" > value="drop-and-create-tables"/> > > > > http://www.oracle.com/technology/products/ias/toplink/JPA/essentials/toplink-jpa-extensions.html > > complete hibernate provider example is located at > http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html/configuration.html > > anyone hear of a persistence provider named "jpa"? > Martin Gainty > __ > Verzicht und Vertraulichkeitanmerkung/Note de déni et de > confidentialité > > 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: Wed, 12 Aug 2009 19:19:27 + > > From: javadeveloper...@yahoo.co.uk > > Subject: persistence unit can not be found during > test > > To: users@maven.apache.org > > > > I encouter a problem when running maven test + jpa + > mysql. The report result always shows that `No Persistence > provider for EntityManager named jpa' (where jpa is the > persistent-unit name specified in the persistence.xml under > src/main/resources/META-INF). It looks like the test (e.g. > mvn test) can not find the persistence.xml file; however, a > tutorial I found out on the internet - > http://www.stripesbook.com/blog/index.php?/archives/34-Java-Persistence-Maven-2,-JPA,-and-Hibernate-Quickstart.html, > its source code structure is similar to mine and its test > can be executed without a problem. > > > > Where should I specify the persistence.xml path so > that the mvn test will pick up the persistence unit (I try > specify persistence.xml in test/resources/META-INF folder it > doesn't work as well)? Or where should I check that might > cause such problem? > > > > I appreciate any help. > > > > env: debian kernel 2.6.30-1/ java 1.6.0_10/ maven > 2.0.9 > > > > exception: > > > > Caused by: javax.persistence.PersistenceException: No > Persistence provider for EntityManager named jpa > > at > javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89) > > at > javax.persistence.Persist
RE: persistence unit can not be found during test
why not use oracle-toplink such as this example from /src/conf/persistence.xml oracle.toplink.essentials.PersistenceProvider jdbc/someDefinableName someORMap.xml entities/Jar.jar ejbinaction.persistence.Category ejbinaction.persistence.Bid http://www.oracle.com/technology/products/ias/toplink/JPA/essentials/toplink-jpa-extensions.html complete hibernate provider example is located at http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html/configuration.html anyone hear of a persistence provider named "jpa"? Martin Gainty __ Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité 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: Wed, 12 Aug 2009 19:19:27 + > From: javadeveloper...@yahoo.co.uk > Subject: persistence unit can not be found during test > To: users@maven.apache.org > > I encouter a problem when running maven test + jpa + mysql. The report result > always shows that `No Persistence provider for EntityManager named jpa' > (where jpa is the persistent-unit name specified in the persistence.xml under > src/main/resources/META-INF). It looks like the test (e.g. mvn test) can not > find the persistence.xml file; however, a tutorial I found out on the > internet - > http://www.stripesbook.com/blog/index.php?/archives/34-Java-Persistence-Maven-2,-JPA,-and-Hibernate-Quickstart.html, > its source code structure is similar to mine and its test can be executed > without a problem. > > Where should I specify the persistence.xml path so that the mvn test will > pick up the persistence unit (I try specify persistence.xml in > test/resources/META-INF folder it doesn't work as well)? Or where should I > check that might cause such problem? > > I appreciate any help. > > env: debian kernel 2.6.30-1/ java 1.6.0_10/ maven 2.0.9 > > exception: > > Caused by: javax.persistence.PersistenceException: No Persistence provider > for EntityManager named jpa > at > javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89) > at > javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60) > at > exmample.domain.PersistenceProvider.(PersistenceProvider.java:35) > ... 63 more > > > PersistenceProvider.java > > public class PersistenceProvider{ > > public static final String PERSISTENCE_UNIT_NAME = "jpa"; > private static EntityManagerFactory factory; > > static { > try { > factory = > Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); > }catch(Throwable t) { > throw new ExceptionInInitializerError(t); > } > } > > public static EntityManagerFactory createPersistenceFactory() { > return factory; > } > > public static void close() { > if(null == factory) > throw new NullPointerException("No EntityManagerFactory > available!"); > factory.close(); > } > } > > persistence.xml > > http://java.sun.com/xml/ns/persistence"; > xmlns:xsi="http://www.23.org/2001/XMLSchema-instance"; > xsi:schemaLocation="http://java.sun.com/ns/persistence > http://java.sun.com/ns/persistence/persistence_1_0.xsd"; > version="1.0"> > > org.hibernate.ejb.HibernatePersistence > > >value="class, hbm"/> > > > > >value="org.hibernate.dialect.MySQLDialect"/> >value="com.mysql.jdbc
Re: persistence unit can not be found during test
Sorry I don't understand very well. Shouldn't maven pick up persistence.xml either specified in the src/main/resources/META-INF or src/test/resources/META-INF? Or what command I need spcify so that when executing `mvn test', maven will pick up persistence.xml that is copied to target/test-classes? Thanks for your help. I appreciate it. --- On Wed, 12/8/09, Brian Fox wrote: > From: Brian Fox > Subject: Re: persistence unit can not be found during test > To: "Maven Users List" > Date: Wednesday, 12 August, 2009, 7:44 PM > your resources will be copied to > /target/test-classes/ so use that, or > better, load it from the classpath, then you aren't path > dependent. > > On Wed, Aug 12, 2009 at 3:19 PM, Neo > Anderson > wrote: > > I encouter a problem when running maven test + jpa + > mysql. The report result always shows that `No Persistence > provider for EntityManager named jpa' (where jpa is the > persistent-unit name specified in the persistence.xml under > src/main/resources/META-INF). It looks like the test (e.g. > mvn test) can not find the persistence.xml file; however, a > tutorial I found out on the internet - > http://www.stripesbook.com/blog/index.php?/archives/34-Java-Persistence-Maven-2,-JPA,-and-Hibernate-Quickstart.html, > its source code structure is similar to mine and its test > can be executed without a problem. > > > > Where should I specify the persistence.xml path so > that the mvn test will pick up the persistence unit (I try > specify persistence.xml in test/resources/META-INF folder it > doesn't work as well)? Or where should I check that might > cause such problem? > > > > I appreciate any help. > > > > env: debian kernel 2.6.30-1/ java 1.6.0_10/ maven > 2.0.9 > > > > exception: > > > > Caused by: javax.persistence.PersistenceException: No > Persistence provider for EntityManager named jpa > > at > javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89) > > at > javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60) > > at > exmample.domain.PersistenceProvider.(PersistenceProvider.java:35) > > ... 63 more > > > > > > PersistenceProvider.java > > > > public class PersistenceProvider{ > > > > public static final String > PERSISTENCE_UNIT_NAME = "jpa"; > > private static EntityManagerFactory > factory; > > > > static { > > try { > > factory = > Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); > > }catch(Throwable t) { > > throw new > ExceptionInInitializerError(t); > > } > > } > > > > public static EntityManagerFactory > createPersistenceFactory() { > > return factory; > > } > > > > public static void close() { > > if(null == factory) > > throw new > NullPointerException("No EntityManagerFactory available!"); > > factory.close(); > > } > > } > > > > persistence.xml > > > > http://java.sun.com/xml/ns/persistence"; > > xmlns:xsi="http://www.23.org/2001/XMLSchema-instance"; > > xsi:schemaLocation="http://java.sun.com/ns/persistence > > http://java.sun.com/ns/persistence/persistence_1_0.xsd"; > > version="1.0"> > > > > > org.hibernate.ejb.HibernatePersistence > > > > > > name="hibernate.archive.autodetection" > > value="class, > hbm"/> > > > > name="hibernate.show_sql" value="true"/> > > name="hibernate.format_sql" value="true"/> > > > > name="hibernate.dialect" > > > value="org.hibernate.dialect.MySQLDialect"/> > > name="hibernate.connection.driver_class" > > > value="com.mysql.jdbc.Driver"/> > > name="hibernate.connection.url" > > > value="jdbc:mysql://localhost/demo"/> > > > > name="hibernate.connection.username" value="root"/> > > name="hibernate.connection.password" value="*"/> > > > > > > > > > &
Re: persistence unit can not be found during test
your resources will be copied to /target/test-classes/ so use that, or better, load it from the classpath, then you aren't path dependent. On Wed, Aug 12, 2009 at 3:19 PM, Neo Anderson wrote: > I encouter a problem when running maven test + jpa + mysql. The report result > always shows that `No Persistence provider for EntityManager named jpa' > (where jpa is the persistent-unit name specified in the persistence.xml under > src/main/resources/META-INF). It looks like the test (e.g. mvn test) can not > find the persistence.xml file; however, a tutorial I found out on the > internet - > http://www.stripesbook.com/blog/index.php?/archives/34-Java-Persistence-Maven-2,-JPA,-and-Hibernate-Quickstart.html, > its source code structure is similar to mine and its test can be executed > without a problem. > > Where should I specify the persistence.xml path so that the mvn test will > pick up the persistence unit (I try specify persistence.xml in > test/resources/META-INF folder it doesn't work as well)? Or where should I > check that might cause such problem? > > I appreciate any help. > > env: debian kernel 2.6.30-1/ java 1.6.0_10/ maven 2.0.9 > > exception: > > Caused by: javax.persistence.PersistenceException: No Persistence provider > for EntityManager named jpa > at > javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89) > at > javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60) > at > exmample.domain.PersistenceProvider.(PersistenceProvider.java:35) > ... 63 more > > > PersistenceProvider.java > > public class PersistenceProvider{ > > public static final String PERSISTENCE_UNIT_NAME = "jpa"; > private static EntityManagerFactory factory; > > static { > try { > factory = > Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); > }catch(Throwable t) { > throw new ExceptionInInitializerError(t); > } > } > > public static EntityManagerFactory createPersistenceFactory() { > return factory; > } > > public static void close() { > if(null == factory) > throw new NullPointerException("No > EntityManagerFactory available!"); > factory.close(); > } > } > > persistence.xml > > http://java.sun.com/xml/ns/persistence"; > xmlns:xsi="http://www.23.org/2001/XMLSchema-instance"; > xsi:schemaLocation="http://java.sun.com/ns/persistence > http://java.sun.com/ns/persistence/persistence_1_0.xsd"; > version="1.0"> > > org.hibernate.ejb.HibernatePersistence > > > value="class, hbm"/> > > > > > value="org.hibernate.dialect.MySQLDialect"/> > value="com.mysql.jdbc.Driver"/> > value="jdbc:mysql://localhost/demo"/> > > > > > > > > > pom.xml > > > > > > org.beanshell > bsh > 2.0b4 > > > > > aspectj > aspectjrt > 1.5.4 > > > > > org.apache.tapestry > tapestry-core > ${tapestry-release-version} > > > org.apache.tapestry > tapestry-ioc > ${tapestry-release-version} > > > org.apache.tapestry > tapestry5-annotations > ${tapestry-release-version} > > > > > org.hibernate > hibernate > 3.2.2.ga > > > jta > javax.transaction > > > > > c3p0 > c3p0 > 0.9.0 > > > org.apache.tapestry > tapestry-hibernate > 5.1.0.5 > > > org.apache.tapestry > tapestry-hibernate-core > 5.1.0.5 > > > org.apache.geronimo.specs > geronimo-jta_1.0.1B_spec > 1.1 > > > org.hibernate > hibernate-annotations > 3.2.1.ga > > > > > mysql > mysql-connector-java > 3.1.12 > > > > > junit > junit > 4.6 > test > > > > javax.servlet > servlet-api > 2.5 > provided > > > > >
persistence unit can not be found during test
I encouter a problem when running maven test + jpa + mysql. The report result always shows that `No Persistence provider for EntityManager named jpa' (where jpa is the persistent-unit name specified in the persistence.xml under src/main/resources/META-INF). It looks like the test (e.g. mvn test) can not find the persistence.xml file; however, a tutorial I found out on the internet - http://www.stripesbook.com/blog/index.php?/archives/34-Java-Persistence-Maven-2,-JPA,-and-Hibernate-Quickstart.html, its source code structure is similar to mine and its test can be executed without a problem. Where should I specify the persistence.xml path so that the mvn test will pick up the persistence unit (I try specify persistence.xml in test/resources/META-INF folder it doesn't work as well)? Or where should I check that might cause such problem? I appreciate any help. env: debian kernel 2.6.30-1/ java 1.6.0_10/ maven 2.0.9 exception: Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named jpa at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60) at exmample.domain.PersistenceProvider.(PersistenceProvider.java:35) ... 63 more PersistenceProvider.java public class PersistenceProvider{ public static final String PERSISTENCE_UNIT_NAME = "jpa"; private static EntityManagerFactory factory; static { try { factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); }catch(Throwable t) { throw new ExceptionInInitializerError(t); } } public static EntityManagerFactory createPersistenceFactory() { return factory; } public static void close() { if(null == factory) throw new NullPointerException("No EntityManagerFactory available!"); factory.close(); } } persistence.xml http://java.sun.com/xml/ns/persistence"; xmlns:xsi="http://www.23.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://java.sun.com/ns/persistence http://java.sun.com/ns/persistence/persistence_1_0.xsd"; version="1.0"> org.hibernate.ejb.HibernatePersistence pom.xml org.beanshell bsh 2.0b4 aspectj aspectjrt 1.5.4 org.apache.tapestry tapestry-core ${tapestry-release-version} org.apache.tapestry tapestry-ioc ${tapestry-release-version} org.apache.tapestry tapestry5-annotations ${tapestry-release-version} org.hibernate hibernate 3.2.2.ga jta javax.transaction c3p0 c3p0 0.9.0 org.apache.tapestry tapestry-hibernate 5.1.0.5 org.apache.tapestry tapestry-hibernate-core 5.1.0.5 org.apache.geronimo.specs geronimo-jta_1.0.1B_spec 1.1 org.hibernate hibernate-annotations 3.2.1.ga mysql mysql-connector-java 3.1.12 junit junit 4.6 test javax.servlet servlet-api 2.5 provided jecommerce org.apache.maven.plugins maven-compiler-plugin 1.5 1.5 true org.apache.maven.plugins maven-war-plugin