User12111111
User12111111

Reputation: 1219

JPA: Error while trying to load persistence unit

This is a web application, written using Restful (Jersey) and JPA2. I have created a war file, and was trying to deploy this war on CentOS under Tomcat 8. When I start the tomcat, the tomcat launched successfully. But when I try to access a URL, I see the following error.

    Exception Description: An exception was thrown while trying to load persistence unit at url: file:/opt/tomcat/webapps/DSystem.war
    Internal Exception: Exception [EclipseLink-30004] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
    Exception Description: An exception was thrown while processing persistence.xml from URL: file:/opt/tomcat/webapps/DSystem.war
    Internal Exception: java.net.MalformedURLException

Here is the Maven pom.xml file.

    <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>com.d.dsystem</groupId>
        <artifactId>DSystem</artifactId>
        <packaging>war</packaging>
        <version>1.0.0-SNAPSHOT</version>
        <name>DSystem</name>
        <build>
            <finalName>DSystem</finalName>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.5.1</version>
                    <inherited>true</inherited>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.glassfish.jersey</groupId>
                    <artifactId>jersey-bom</artifactId>
                    <version>${jersey.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.glassfish.jersey.containers</groupId>
                <artifactId>jersey-container-servlet-core</artifactId>
            </dependency>
            <dependency>
                <groupId>org.glassfish.jersey.media</groupId>
                <artifactId>jersey-media-moxy</artifactId>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <version>3.1.0</version>
            </dependency>
            <dependency>
                <groupId>org.eclipse.persistence</groupId>
                <artifactId>eclipselink</artifactId>
                <version>2.6.0</version>
            </dependency>
            <!--Externally adding at jar file for Maven-->
            <dependency>
                <groupId>org.mysql</groupId>
                <artifactId>mysql</artifactId>
                <scope>system</scope>
                <version>3.0.11</version>
                <systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/mysql-connector-java-3.0.11-stable-bin.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j</artifactId>
                <scope>system</scope>
                <version>1.2.8</version>
                <systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/log4j-1.2.8.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>com.sun.jersey.contribs</groupId>
                <artifactId>jersey-apache-client</artifactId>
                <version>1.19</version>
            </dependency>
            <dependency>
                <groupId>org.glassfish.jersey.ext</groupId>
                <artifactId>jersey-mvc-mustache</artifactId>
            </dependency>
        </dependencies>
        <properties>
            <jersey.version>2.22</jersey.version>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
    </project>

persistence.xml file is at src/main/java/META-INF location. Here is my persistence.xml file has

    <?xml version="1.0" encoding="UTF-8" ?>
    <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_2_0.xsd"
      version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
      <persistence-unit name="DSystemService" transaction-type="RESOURCE_LOCAL">
        <class>com.d.dsystem.db.Trans</class>
        <properties>
          <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.url"
            value="jdbc:mysql://localhost:3306/dsystemdb"/>
          <property name="javax.persistence.jdbc.user" value="root" />
          <property name="javax.persistence.jdbc.password" value="" />
          <!-- EclipseLink should create the database schema automatically -->
          <property name="eclipselink.deploy-on-startup" value="true"/>
          <property name="eclipselink.ddl-generation.output-mode" value="database" /> 
          <property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
        </properties>
      </persistence-unit>
    </persistence>

Here is my code:

    EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("DSystemService");
    EntityManager entityManager = entityManagerFactory.createEntityManager();
    entityManager.persist(transObj);
    entityManager.getTransaction().commit();

The same war file work on tomcat 8 windows, Jetty 9 on Ubuntu. I am not sure, why I see this error. Can someone tell me what's wrong with the deployment on CentOS.

Any help is appreciated.

Upvotes: 2

Views: 2176

Answers (1)

codefan-BK
codefan-BK

Reputation: 310

This might happen because of an yet unsolved bug in EclipseLink. See Eclipse Bugzilla Bug #353121 also discussed here: Eclipse Forum

The user mentions a workaround that helped in his case:

By the way, I found a workaround that does not require patching of code : I disabled the "Serve modules without publishing" of the Tomcat configuration in Eclipse.

Upvotes: 1

Related Questions