首页 > 解决方案 > Wildfly Eclipselink checkForUnregisteredExistingObject NullPointerException

问题描述

我有一个问题,我无法将简单的对象保存到数据库。该项目最初使用的是 Hibernate,但我改为使用 Eclipselink。

我有其他带有 Eclipselink 的项目,但没有这个配置和这个服务器(Wildfly 10.x)。

我不确定是否会与某些 JBOSS 库发生冲突。

这是错误:

20:54:34,322 WARNING [javax.enterprise.resource.webcontainer.jsf.lifecycle] (default task-12) javax.ejb.EJBException: java.lang.NullPointerException: javax.el.ELException: javax.ejb.EJBException: java.lang.NullPointerException    
2018-05-09 20:54:34 ERROR [context:222] javax.ejb.EJBException: java.lang.NullPointerException    
Caused by: java.lang.NullPointerException
            at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.checkForUnregisteredExistingObject(UnitOfWorkImpl.java:773)

我的POM是:

<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>au.com.chillipepper.pfitools</groupId>
<artifactId>portal</artifactId>
<version>${warVersion}</version>
<packaging>war</packaging>

<repositories>
    <repository>
        <id>jboss-enterprise-maven-repository</id>
        <url>https://maven.repository.redhat.com/ga/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>prime-repo</id>
        <name>PrimeFaces Maven Repository</name>
        <url>http://repository.primefaces.org</url>
        <layout>default</layout>
    </repository>

    <repository>
        <url>http://download.eclipse.org/rt/eclipselink/maven.repo/</url>
        <id>eclipselink</id>
        <layout>default</layout>
        <name>Repository for library Library[eclipselink]</name>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>jboss-enterprise-maven-repository</id>
        <url>https://maven.repository.redhat.com/ga/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

<properties>
    <!-- Explicitly declaring the source encoding eliminates the following
        message: -->
    <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
        resources, i.e. build is platform dependent! -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <warVersion>0.0.1</warVersion>

    <!-- JBoss dependency versions -->
    <version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin>

    <!-- Define the version of the JBoss BOMs we want to import to specify tested stacks. -->
    <version.jboss.bom.eap>7.1.1.GA</version.jboss.bom.eap>

    <!-- other plug-in versions -->
    <version.surefire.plugin>2.10</version.surefire.plugin>
    <version.war.plugin>2.1.1</version.war.plugin>

    <!-- maven-compiler-plugin -->
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
</properties>

<dependencyManagement>
    <dependencies>
        <!-- JBoss distributes a complete set of Java EE APIs including a Bill
    of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection)
    of artifacts. We use this here so that we always get the correct versions
    of artifacts. Here we use the jboss-eap-javaee7-with-tools stack (you can read this as
    the JBoss stack of the Java EE APIs, with some extras tools for your project, such
    as Arquillian for testing) -->
        <dependency>
            <groupId>org.jboss.bom</groupId>
            <artifactId>jboss-eap-javaee7-with-tools</artifactId>
            <version>${version.jboss.bom.eap}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>

    <!-- Import the JSF API, we use provided scope as the API is included in JBoss EAP -->
    <dependency>
        <groupId>org.jboss.spec.javax.faces</groupId>
        <artifactId>jboss-jsf-api_2.2_spec</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Import the CDI API, we use provided scope as the API is included in JBoss EAP -->
    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.sun.mail/javax.mail -->
    <dependency>
        <groupId>com.sun.mail</groupId>
        <artifactId>javax.mail</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.jboss.spec.javax.el/jboss-el-api_3.0_spec -->
    <dependency>
        <groupId>org.jboss.spec.javax.el</groupId>
        <artifactId>jboss-el-api_3.0_spec</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Import the JPA API, we use provided scope as the API is included in JBoss EAP -->
    <!-- 
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <scope>provided</scope>
    </dependency>
     -->

    <!-- ECLIPSELINK -->
    <!-- https://mvnrepository.com/artifact/org.eclipse.persistence/org.eclipse.persistence.jpa -->
    <!-- 
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>org.eclipse.persistence.jpa</artifactId>
        <version>2.7.1</version>
    </dependency>
     -->

     <!-- https://mvnrepository.com/artifact/org.eclipse.persistence/eclipselink -->
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>2.5.2</version>
        <scope>provided</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.eclipse.persistence/javax.persistence -->
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>javax.persistence</artifactId>
        <version>2.0.3</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.jboss.spec.javax.servlet/jboss-servlet-api_3.1_spec -->
    <dependency>
        <groupId>org.jboss.spec.javax.servlet</groupId>
        <artifactId>jboss-servlet-api_3.1_spec</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Import the EJB API, we use provided scope as the API is included in JBoss EAP -->
    <dependency>
        <groupId>org.jboss.spec.javax.ejb</groupId>
        <artifactId>jboss-ejb-api_3.2_spec</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- 
    <dependency>
        <groupId>javax.ejb</groupId>
        <artifactId>ejb-api</artifactId>
        <version>3.0</version>
    </dependency>
     -->

    <!-- Test dependencies -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.arquillian.protocol</groupId>
        <artifactId>arquillian-protocol-servlet</artifactId>
        <scope>test</scope>
    </dependency>

    <!-- PRIMEFACES -->
    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>6.1</version>
    </dependency>
    <dependency>
        <groupId>org.primefaces.extensions</groupId>
        <artifactId>primefaces-extensions</artifactId>
        <version>6.1.0</version>
    </dependency>

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
    </dependency>

    <!-- 
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.25</version>
    </dependency>
     -->

    <dependency>
        <groupId>commons-beanutils</groupId>
        <artifactId>commons-beanutils</artifactId>
        <version>1.8.3</version>
    </dependency>

    <dependency>
      <groupId>org.jasypt</groupId>
      <artifactId>jasypt</artifactId>
      <version>1.9.2</version>
      <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>4.0.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.9</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.6</version>
    </dependency>

</dependencies>

<build>
    <!-- FILTER FILE TO REPLACE MAVEN VALUES -->
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

    <!-- Maven will append the version to the finalName (which is the name
        given to the generated WAR, and hence the context root) -->
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>${version.war.plugin}</version>
            <configuration>
                <!-- Java EE doesn't require web.xml, Maven needs to catch up! -->
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
        </plugin>

        <!-- Surefire plug-in is responsible for running tests
            as part of project build -->
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${version.surefire.plugin}</version>
        </plugin>
        <!-- The WildFly plug-in deploys the WAR to a local JBoss EAP container -->
        <!-- To use, run: mvn package wildfly:deploy -->
        <plugin>
            <groupId>org.wildfly.plugins</groupId>
            <artifactId>wildfly-maven-plugin</artifactId>
            <version>${version.wildfly.maven.plugin}</version>
            <!-- 
            <configuration>
                <hostname>CPM-WIN-SVR1</hostname>
                <port>9990</port>
                <username>jenkins</username>
                <password>jenkins-1004</password>
            </configuration>
             -->
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <!-- The default profile skips all tests, though you can tune it
            to run just unit tests based on a custom pattern -->
        <!-- Separate profiles are provided for running all tests, including
            Arquillian tests that execute in the specified container -->
        <id>default</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </plugin>
            </plugins>
        </build>

    </profile>
    <profile>
        <!-- An optional Arquillian testing profile that executes tests
            in your JBoss EAP instance -->
        <!-- This profile will start a new JBoss EAP instance, and execute
            the test, shutting it down when done -->
        <!-- Run with: mvn clean test -Parq-wildfly-managed -->
        <id>arq-wildfly-managed</id>
        <dependencies>
            <dependency>
                <groupId>org.wildfly.arquillian</groupId>
                <artifactId>wildfly-arquillian-container-managed</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </profile>

    <profile>
        <!-- An optional Arquillian testing profile that executes tests
            in a remote JBoss EAP instance -->
        <!-- Run with: mvn clean test -Parq-wildfly-remote -->
        <id>arq-wildfly-remote</id>
        <dependencies>
            <dependency>
                <groupId>org.wildfly.arquillian</groupId>
                <artifactId>wildfly-arquillian-container-remote</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </profile>

</profiles>

持久性.xml

    <?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
    xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="primary" transaction-type="JTA">
        <!-- 
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
         -->
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>java:jboss/datasources/PFITools</jta-data-source>
        <mapping-file>jpa/UserDAO.xml</mapping-file>
        <mapping-file>jpa/QuestionDAO.xml</mapping-file>
        <mapping-file>jpa/OptionDAO.xml</mapping-file>
        <mapping-file>jpa/AssessmentQuestionDAO.xml</mapping-file>
        <mapping-file>jpa/QuestionTypeDAO.xml</mapping-file>
        <mapping-file>jpa/AssessmentQuestionAnswerDAO.xml</mapping-file>
        <mapping-file>jpa/ArtifactDAO.xml</mapping-file>
        <mapping-file>jpa/CompanyDAO.xml</mapping-file>
        <mapping-file>jpa/AssessmentCaseDAO.xml</mapping-file>
        <mapping-file>jpa/AssessmentDAO.xml</mapping-file>
        <mapping-file>jpa/AssessmentQuestionCommentDAO.xml</mapping-file>
        <mapping-file>jpa/CaseCheckListDAO.xml</mapping-file>
        <mapping-file>jpa/ActivityDAO.xml</mapping-file>
        <mapping-file>jpa/StakeholderDAO.xml</mapping-file>
        <mapping-file>jpa/StakeholderContactDAO.xml</mapping-file>
        <class>au.com.chillipepper.pfitools.portal.vo.FactVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.ActivityVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.ActivityLogVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.ArtifactVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.ArtifactClassificationVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.ArtifactTypeVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.AssessmentVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.AssessmentCaseVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.AssessmentQuestionVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.AssessmentQuestionAnswerVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.AssessmentQuestionCommentVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.AssessmentSectionVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.BreachOverviewVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.CaseCheckListVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.CaseStakeholderContactVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.CaseVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.CompanyVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.ConfigVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.CountryVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.MilestoneVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.OptionVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.QuestionVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.QuestionTypeVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.StakeholderVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.StakeholderContactVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.StakeholderRequirementVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.StakeholderTypeVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.ThirdPartyVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.UserTypeVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.UserVO</class>
        <class>au.com.chillipepper.pfitools.portal.vo.WorkDiaryVO</class>
        <shared-cache-mode>NONE</shared-cache-mode>

        <properties>
            <property name="eclipselink.logging.level" value="FINEST"/>
            <property name="eclipselink.logging.parameters" value="true"/>
            <property name="eclipselink.query-results-cache" value="false"/>
            <property name="eclipselink.target-database" value="PostgreSQL"/>
            <property name="eclipselink.jdbc.cache-statements" value="false"/>
        </properties>
    </persistence-unit>
</persistence>

我尝试了其他较新版本的 Eclipselink,但无法正常工作。

谢谢。

标签: javanulleclipselinkwildfly

解决方案


推荐阅读