2 Replies Latest reply on Oct 29, 2007 9:03 AM by Damian Harvey

    persistence.xml and TestNG

    Damian Harvey Master

      I'm sure I'm being an idiot on this, but I'm trying to get a unit test working with an EntityManagerFactory (as per the Seam reference) but I can't get it to find my persistence.xml.

      The error I am getting is:

      INFO 29-10 12:13:49,503 [org.hibernate.ejb.Version.<clinit>():15] Hibernate EntityManager 3.2.0.GA
      INFO 29-10 12:13:49,524 [org.hibernate.cfg.annotations.Version.<clinit>():15] Hibernate Annotations 3.2.0.GA
      INFO 29-10 12:13:49,534 [org.hibernate.cfg.Environment.<clinit>():500] Hibernate 3.2.1
      INFO 29-10 12:13:49,541 [org.hibernate.cfg.Environment.<clinit>():533] hibernate.properties not found
      INFO 29-10 12:13:49,543 [org.hibernate.cfg.Environment.buildBytecodeProvider():667] Bytecode provider name : cglib
      INFO 29-10 12:13:49,549 [org.hibernate.cfg.Environment.<clinit>():584] using JDK 1.4 java.sql.Timestamp handling
      INFO 29-10 12:13:49,632 [org.hibernate.ejb.Ejb3Configuration.configure():202] Could not find any META-INF/persistence.xml file in the classpath
      WARN 29-10 12:13:49,679 [org.hibernate.connection.UserSuppliedConnectionProvider.configure():23] No connection properties specified - the user must supply JDBC connections
      FAILED CONFIGURATION: @BeforeTest init
      javax.persistence.PersistenceException: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
       at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:698)
       at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
       at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
       at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
       at com.locuslive.odyssey.test.TestUnLocodeList.init(TestUnLocodeList.java:36)
      Caused by: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
       at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
       at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
       at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:409)
       at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:119)
       at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2006)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1289)
       at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:691)
       ... 23 more

      It's a standard Seam Gen'd project with 3 persistence.xmls (dev, test, prod) in the resources/META-INF directory. I've added the 4 test jars (lib/test/jboss-embedded-all.jar, lib/test/hibernate-all.jar, lib/test/thirdparty-all.jar and lib/test/jboss-deployers.jar) to the top of the TestNG User classpath.

      I've seen in some other posts that people have had success moving the persistence.xml file around. This hasn't worked for me.

      My persistence.xml looks like this:
      <?xml version="1.0" encoding="UTF-8"?>
      <!-- Persistence deployment descriptor for dev profile -->
      <persistence 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"
       version="1.0">
      
       <persistence-unit name="Odyssey0.5.0">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/Odyssey0.5.0Datasource</jta-data-source>
       <properties>
       <property name="hibernate.hbm2ddl.auto" value="validate"/>
       <property name="hibernate.cache.use_query_cache" value="true"/>
       <property name="hibernate.show_sql" value="true"/>
       <property name="jboss.entity.manager.factory.jndi.name" value="java:/Odyssey0.5.0EntityManagerFactory"/>
       </properties>
       </persistence-unit>
      </persistence>
      


      Can anyone suggest a solution? Am I missing something obvious?

      Thanks,

      Damian.



        • 1. Re: persistence.xml and TestNG
          Pete Muir Master

          How are you running the test - from seam-gen'd build.xml? Or eclipse plugin? You need to make sure that on your classpath for the test is a file exactly /META-INF/persistence.xml - seam-gen's build.xml copies /resources/META-INF/persistence-test.xml to /test-build/META-INF/persistence.xml and adds test-build to the classpath.

          • 2. Re: persistence.xml and TestNG
            Damian Harvey Master

            Thanks for the quick response Pete.

            I'm using TestNG Eclipse plugin. I ran the ant buildtest task to create the test-build directory and then added this to my User classpath. This solved the problem with the test not being able to find the persistence.xml and all is working well.

            Very grateful.

            Cheers,

            Damian.