2017-08-22 4 views
0

私は最近、開発マシンを切り替えて、永続データベースからオブジェクトを取得/これは、私の新しいマシンでwebappプロジェクトをデバッグしようとすると発生します。 これは私の古いノートパソコンでは動作しますが、何とか新しいノートパソコンでは動作しません。私もwebappをサーバーにデプロイしました。そこにはすべて期待どおりに動作します。Eclipselink:永続データベースへのオブジェクトの書き込みエラー/永続データベースからのオブジェクトの取得

データベースと対話しながら、私は次の2つのエラーメッセージが表示されます:

は、オブジェクトをデータベースに書き込む:データベースに書き込むための

SEVERE: Exception sending context initialized event to listener instance of class org.example.webapp.startup.ServletContextClass 
java.lang.IllegalArgumentException: Object: [email protected] is not a known entity type. 
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4222) 
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:496) 
    at org.example.webapp.changelog.dao.ChangeLogDao.addChangeLog(ChangeLogDao.java:42) 
    at org.example.webapp.startup.ServletContextClass.initializeChangeLog(ServletContextClass.java:104) 
    at org.example.webapp.startup.ServletContextClass.contextInitialized(ServletContextClass.java:59) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5221) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 

コード:

オブジェクトを取得
public void addChangeLog(ChangeLog changeLog, EntityManagerFactory emf) { 

    String changeLogId = changeLog.getModelResource(); 

    if(!contentProvider.containsKey(changeLogId)) { 

     //create new user 
     EntityManager em = emf.createEntityManager(); 

     em.getTransaction().begin(); 

     em.persist(changeLog); 

     em.getTransaction().commit(); 
     em.close(); 

     contentProvider.put(changeLogId, changeLog); 
    } 

をデータベースから:

SEVERE: Exception sending context initialized event to listener instance of class org.example.webapp.startup.ServletContextClass 
java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
Exception Description: Problem compiling [SELECT c FROM ChangeLog c]. 
[14, 23] The abstract schema type 'ChangeLog' is unknown. 
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1585) 
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1605) 
    at org.example.webapp.startup.ServletContextClass.contextInitialized(ServletContextClass.java:59) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5221) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 

コードデータベースから読み取るために:

package org.example.utility.trs.objects; 

import javax.persistence.Entity; 
import javax.persistence.GeneratedValue; 
import javax.persistence.GenerationType; 
import javax.persistence.Id; 
import javax.persistence.NamedQuery; 
import javax.xml.bind.annotation.XmlAccessType; 
import javax.xml.bind.annotation.XmlAccessorType; 
import javax.xml.bind.annotation.XmlRootElement; 

@Entity 
@NamedQuery(name="ChangeLog.findAll", query="SELECT c FROM ChangeLog c") 
@XmlRootElement 
@XmlAccessorType(XmlAccessType.FIELD) 
public class ChangeLog implements Serializable { 

    private static final long serialVersionUID = 123L; 

    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    private Long changeLogId; 
    ... 
} 

これはpersistence.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="webapp-name" transaction-type="RESOURCE_LOCAL"> 

     <class>org.example.utility.trs.objects.ChangeLog</class> 

     <exclude-unlisted-classes>false</exclude-unlisted-classes> 

     <properties>   

      <!-- mysql persistence driver --> 
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/persistence"/> 
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> 
      <property name="javax.persistence.jdbc.username" value="admin"/> 
      <property name="javax.persistence.jdbc.password" value="password"/> 

      <!-- EclipseLink should create the database schema automatically --> 
      <property name="eclipselink.ddl-generation.output-mode" value="database" /> 
      <property name="javax.persistence.jdbc.user" value="admin"/> 
     </properties> 
    </persistence-unit> 
</persistence> 

はの一部であり、ここで

List<ChangeLog> changeLogList = em.createQuery("SELECT c FROM ChangeLog c", 
               ChangeLog.class).getResultList(); 

ChangeLogクラスがどのように見えるかです永続ライブラリを含むファイルpom.xml

<!-- persistence api --> 
<dependency> 
    <groupId>org.hibernate.javax.persistence</groupId> 
    <artifactId>hibernate-jpa-2.0-api</artifactId> 
    <version>1.0.1.Final</version> 
</dependency> 

<dependency> 
    <groupId>org.eclipse.persistence</groupId> 
    <artifactId>eclipselink</artifactId> 
    <version>2.5.0</version> 
</dependency> 

私は、データベースに接続することができますし、私は私の古い開発マシン上で作成して読むことができたコンテンツを持つテーブルがある:任意のassistenceこの場合、私はファイル全体を投稿することができます。 したがって、コード内の実際の問題よりもeclipselinkの設定で問題が発生していると思います。おそらく、EclipseプロジェクトのJPAファセットの構成に関する問題です。

しかし、この問題のデバッグ方法はわかりません。

一方、ChangeLogクラスは、ローカルのMavenリポジトリに格納されている別のプロジェクトのもので、webappプロジェクトでは定義されていません。だからこれは問題かもしれません。しかし、これは私の古いマシンでは決して問題ではありませんでした。

すべてのヘルプは、だから、いくつかのテストの後、私は最終的に何が悪かったのかを考え出し

答えて

0

を高く評価しています。他の誰かがこの問題に遭遇した場合、私はこれをここに残します。

新しい開発マシンにコードをデプロイしているうちに、私のpom.xmlファイルのいくつかの依存バージョンが変更されたことが判明しました。そこで、eclipselink APIのバージョン2.6.4のデータベーステーブルを作成しました。

新しい開発マシンでは、バージョン2.5に変更し、データベースからオブジェクトの抽出を壊したプロジェクトを再コンパイルしました。

バージョンを元に戻すと、再び機能しました。

関連する問題