Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JPA 2.0和EclipseLink 2.0的身份验证错误_Jpa_Eclipselink - Fatal编程技术网

JPA 2.0和EclipseLink 2.0的身份验证错误

JPA 2.0和EclipseLink 2.0的身份验证错误,jpa,eclipselink,Jpa,Eclipselink,我是JPA的新手。我使用的是maven、Eclipselink2.0和JPA2.0。我已经使用数据库连接创建了实体。这是我的persistence.xml <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instan

我是JPA的新手。我使用的是maven、Eclipselink2.0和JPA2.0。我已经使用数据库连接创建了实体。这是我的persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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_2_0.xsd">
    <persistence-unit name="certifications" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/com/ni/ds_edata_soa_nontx</jta-data-source>
        <class>com.ni.apps.engineering.certification.entities.NicdsCliCertificationStg</class>
        <class>com.ni.apps.engineering.certification.entities.NicdsCliCertificationStgPK</class>
        <class>com.ni.apps.engineering.certification.entities.NicdsCliUpMapping</class>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>          
        <properties>                        
            <property name="javax.persistence.jdbc.password" value="soa_user"/>
            <property name="javax.persistence.jdbc.user" value="soa_user"/>
            <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
            <property name="eclipselink.logging.level.sql" value="FINE"/>           
        </properties>       
    </persistence-unit>
</persistence>

您使用的是应用服务器提供的JTA数据源,因此EclipseLink已经初始化了EntityManager。我认为您不需要额外的属性,因为这样EclipseLink就可以从数据源创建连接

ds.getConnection(username, password);
而是

ds.getConnection();
如果适用,请尝试删除属性javax.persistence.jdbc.password、javax.persistence.jdbc.user和javax.persistence.jdbc.driver以及ee

编辑:您使用的EclipseLink配置为从应用服务器(在您的案例中是WebLogic)使用,因为您使用JTA数据源和JNDI查找从应用服务器获取数据源连接。 但是您使用EclipseLink的方式是在非JavaEE环境中使用的,例如独立JavaSE客户端(请参阅)

如果您在某个地方需要EntityManager,请让WebLogic进行初始化,例如,在Servlet中,它将如下所示:

@WebServlet(urlPatterns = { "/Test" })
public class TestServlet {
  @PersistenceContext(unitName = "certifications")
  private EntityManager entityManager;
}

我试过了,但没用。我添加了更多的信息。谢谢您能否从WebLogic控制台验证数据源连接是否正常工作?可能是您在WebLogic数据源配置中使用了用户“NI”,而其用户名或密码在WebLogic中定义不正确。否,WebLogic数据源具有完全不同的用户/密码组合。它与我在persistence.xml上的相同
@WebServlet(urlPatterns = { "/Test" })
public class TestServlet {
  @PersistenceContext(unitName = "certifications")
  private EntityManager entityManager;
}