2017-11-14 13 views
0

以下のコードを使用してEntityManagerを検索しようとしていますが、エラーが発生しています。私はそれをgoogledが、私はそれから何も得ることができませんでした。 これはジャーの問題のためです。私にいくつかの指針を案内してください。weblogic上のJPA EntityManagerのルックアップに関するクラスキャスト例外

私はweblogicバージョン12.1.3を使用しています。 JNDIツリーで

- >私は、JNDI名 "jpaem" を持っても、私はこのJNDIのために、それに気づいた - それは、クラスを示す: weblogic.jdbc.common.internal.RmiDataSource_12130_WLStub

Exception in thread "main" java.lang.ClassCastException: weblogic.jdbc.common.internal.RmiDataSource_12130_WLStub cannot be cast to javax.persistence.EntityManager 
    at JNDITest.main(JNDITest.java:33) 

EntityManager entityManager = (EntityManager) context.lookup("jpaem"); 

My persistance.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="Eclipselink_JPA" transaction-type="JTA"> 
      <jta-data-source>jpaem</jta-data-source> 
      <class>jpa.Faxerror</class> 
      <properties> 
       <property name="eclipselink.target-database" value="Oracle" /> 
       <property name="eclipselink.target-server" value="WebLogic" /> 
    <property name="javax.persistence.jtaDataSource" value="jpaem"/> 
      </properties> 
     </persistence-unit> 
    </persistence> 

答えて

0

手動でEntityManagerを検索する特段の理由がない場合はall the possible ways of acquiring an EntityManagerから、私はそれがのname属性を参照していますことを容易に

@PersistenceContext(unitName = "Eclipselink_JPA") 
private EntityManager entityManager; 

注意していいよあなたのpersistence-unit、宣言、あなたのjta-data-sourceではありません。それを見ると、エンティティマネージャではなく、データソースが返されます。

関連する問題