unable to get openxava to work with maven

Ram
2012-03-04
2012-12-04
  • Ram
    Ram
    2012-03-04

    Hi friends,

    With lots of failed-attempts from my side to get this to work I am writing, please help me out…
    I am trying to setup an openxava project using maven and trying to deploy on Tomcat 7.
    As a start, I followed this link http://code.google.com/p/openxava-maven/wiki/SampleOXMavenProject.
    I have my directory structure as shown there.
    But after deploy when i try to access the module i get this exception:

    javax.persistence.PersistenceException: No Persistence provider for EntityManager named default
    

    I have checked, the persistence.xml is located at WEB-INF/classes/META-INF/persistence.xml in the generated war

    My persistence.xml looks like:

    <?xml version="1.0" encoding="UTF-8"?>
    <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">
                 
        <!-- Tomcat + mysql -->
        <persistence-unit name="default">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <non-jta-data-source>java:comp/env/jdbc/alltimeAdmin</non-jta-data-source>
            <class>org.openxava.session.GalleryImage</class>
            <properties>
                <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
                <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
                <property name="hibernate.connection.url" value="mysql://127.0.0.1:3306/resume" />
                <property name="hibernate.connection.username" value="root" />
                <property name="hibernate.connection.password" value="admin" />         
            </properties>
        </persistence-unit>
        
    </persistence>
    

    Also I have configured the datasource in context.xml which is as below:

        <Resource name="jdbc/alltimeAdmin" auth="Container" type="javax.sql.DataSource"
                   maxActive="100" maxIdle="10" maxWait="10000"
                   username="root" password="admin" driverClassName="com.mysql.jdbc.Driver"
                   url="jdbc:mysql://127.0.0.1:3306/resume"/>
    

    my hibernate.cfg (which is located in WEB-INF/classes) looks like this:

    <!DOCTYPE hibernate-configuration PUBLIC 
        "-//Hibernate/Hibernate Configuration DTD//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
        <session-factory>
              <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
              <property name="hibernate.connection.url">mysql://127.0.0.1:3306/resume</property>
              <property name="hibernate.connection.username">root</property>
              <property name="hibernate.connection.password">admin</property>
              <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
              <property name="hibernate.default_schema">resume</property>
              <property name="show_sql">true</property>
              <property name="format_sql">true</property>
              <property name="order_updates">true</property>
        </session-factory>
    
    </hibernate-configuration>
    

    and finally the most imp, my pom looks like this:

    <project xmlns="http://maven.apache.org/POM/4.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
      http://maven.apache.org/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>rk.xava.test</groupId>
      <artifactId>rk-xava-test</artifactId>
      <packaging>war</packaging>
      <name>rk-xava-test</name>
      <description>OpenXava Sample application</description>
      <version>0.0.1-SNAPSHOT</version>
       <build>
        <finalName>alltimeadmin</finalName>
        <plugins>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
              <source>1.7</source>
              <target>1.7</target>
            </configuration>
          </plugin>
        </plugins>
      </build>
      <dependencies>
        <dependency>
          <groupId>javax.persistence</groupId>
          <artifactId>persistence-api</artifactId>
          <version>1.0</version>
        </dependency>
        <dependency>
          <groupId>org.openxava</groupId>
          <artifactId>openxava</artifactId>
          <version>4m3</version>
        </dependency>
        <dependency>
          <groupId>org.openxava</groupId>
          <artifactId>ox-jdbc-adapters</artifactId>
          <version>4m3</version>
        </dependency>
        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-core</artifactId>
          <version>3.3.1.GA</version>
        </dependency>
        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-annotations</artifactId>
          <version>3.4.0.GA</version>
        </dependency>
        <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>jstl</artifactId>
          <version>1.1.2</version>
        </dependency>
        <!-- original version was 1.0.3 -->
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
          <groupId>com.lowagie</groupId>
          <artifactId>itext</artifactId>
          <version>2.1.7</version>
        </dependency>
        <dependency>
          <groupId>net.sf.ehcache</groupId>
          <artifactId>ehcache</artifactId>
          <version>1.2.3</version>
        </dependency>
        <dependency>
          <groupId>hibernate</groupId>
          <artifactId>hibernate-entitymanager</artifactId>
          <version>3.4.0.GA</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
        </dependency>
        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-validator</artifactId>
          <version>3.1.0.GA</version>
        </dependency>
        <dependency>
          <groupId>javax.activation</groupId>
          <artifactId>activation</artifactId>
          <version>1.1.1</version>
        </dependency>
        <dependency>
          <groupId>asm</groupId>
          <artifactId>asm</artifactId>
          <version>1.5.3</version>
        </dependency>
        
        <dependency>
          <groupId>org.directwebremoting</groupId>
          <artifactId>dwr</artifactId>
          <version>2.0.10</version>
        </dependency>
        <dependency>
          <groupId>commons-beanutils</groupId>
          <artifactId>commons-beanutils</artifactId>
          <version>1.5</version>
        </dependency>
        <dependency>
          <groupId>commons-digester</groupId>
          <artifactId>commons-digester</artifactId>
          <version>1.7</version>
        </dependency>
        <dependency>
          <groupId>commons-fileupload</groupId>
          <artifactId>commons-fileupload</artifactId>
          <version>1.1</version>
        </dependency>
        <dependency>
          <groupId>commons-io</groupId>
          <artifactId>commons-io</artifactId>
          <version>1.4</version>
        </dependency>
        
        <dependency>
          <groupId>cglib</groupId>
          <artifactId>cglib-nodep</artifactId>
          <version>2.2</version>
        </dependency>
        <dependency>
          <groupId>commons-validator</groupId>
          <artifactId>commons-validator</artifactId>
          <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>oro</groupId>
            <artifactId>oro</artifactId>
            <version>2.0.8</version>
        </dependency>
        <!-- Unavailable in public reposes -->
        <dependency>
          <groupId>com.sun</groupId>
          <artifactId>imap</artifactId>
          <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>commons-net</groupId>
            <artifactId>commons-net</artifactId>
            <version>3.0.1</version>
        </dependency>
                    
        <!-- Original version was 3.1.4 but I don't find required version -->
        <dependency>
          <groupId>jasperreports</groupId>
          <artifactId>jasperreports</artifactId>
          <version>3.1.2</version>
        </dependency>
        <!-- http://code.google.com/p/atinject/ 
             JSR-330 JSR-330: Dependency Injection for Java specification.
         -->
        <dependency>
          <groupId>javax.inject</groupId>
          <artifactId>javax.inject</artifactId>
          <version>1</version>
        </dependency>
        <dependency>
          <groupId>jboss</groupId>
          <artifactId>jboss-archive-browsing</artifactId>
          <version>5.0.0.Alpha</version>
        </dependency>
        
        <dependency>
          <groupId>javax.mail</groupId>
          <artifactId>mailapi</artifactId>
          <version>1.4.3</version>
        </dependency>
        <dependency>
          <groupId>org.apache.poi</groupId>
          <artifactId>poi</artifactId>
          <version>3.2-FINAL</version>
        </dependency>
        
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-jdk14</artifactId>
          <version>1.4.2</version>
        </dependency>
    
        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
            <version>1.1</version>
        </dependency>
      </dependencies>
    
     </project>
    

    When I deploy and the generated war and try to access the module via the URL i get this exception:

    javax.persistence.PersistenceException: No Persistence provider for EntityManager named default
        javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
        org.openxava.jpa.XPersistence.getEntityManagerFactory(XPersistence.java:182)
        org.openxava.jpa.XPersistence.createManager(XPersistence.java:108)
           .....
    

    Guys please help me with this ..
    I have been trying very hard to get this work, but just not able to…
    I know once I get this to one thing to work then working with Openxava would be a real pleasure, but right now struggling very badly….

    regards,
    Ram

     
  • Javier Paniza
    Javier Paniza
    2012-03-07

    Hi Ram,

    besides the URL you used there are other references about using OpenXava with Maven:
    http://code.google.com/p/openxava-mavenized/
    http://openxava.wikispaces.com/maven-setup_en

    Unfortunately I never used Maven so I cannot give you first hand tips about your case. Anyways, maybe the problem is not in maven. Try to create your project using the OpenXava distribution and its ant build. If it does not work put here your problem and I'll help you, otherwise compare the war generated by OpenXava builds and the one generated by Maven, in order to find the differences.


    Learn OpenXava by examplesGet the book

     
  • john
    john
    2012-12-04

    This is not a maven build problem. To debug, do 'mvn package', unpack the war and analyze it to see what the correct hibernate configuration ought to be. Once you know what it should be, then it becomes a matter of correcting the maven build towards that end.

    How can it be correct to define the database connection properties in three places: the datasource, the persistence.xml and the hibernate.cfg? Entity Manager conforms to JPA spec and uses the persistence.xml, not the hibernate.cfg file, so drop the hibernate.cfg file. Then, drop url, driver, user/password from persistence.xml because the persistence unit is pointing at the datasource (if that doesn't cause the problem, it is certainly confusing). IF this doesn't work, then refer to the hibernate forums.

     
    Last edit: john 2012-12-04