【问题标题】:Authentication error with JPA 2.0 and EclipseLink 2.0JPA 2.0 和 EclipseLink 2.0 的身份验证错误
【发布时间】:2014-10-21 04:38:36
【问题描述】:

我是 JPA 的新手。我正在使用 maven、eclipselink 2.0 和 jpa 2.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>

这是我在尝试运行应用程序时遇到的错误。

detailMessage "异常 [EclipseLink-4002] (Eclipse Persistence Services - 2.3.1.v20111018-r10243): org.eclipse.persistence.exceptions.DatabaseException\r\n内部异常: java.sql.SQLException: java.sql。 SQLException: 用户: NI,验证失败。\r\n错误代码: 0" (id=114)

如您所见,在我的坚持中没有什么叫做“NI”。唯一称为 NI 的是我从中提取表以创建实体的模式。 JTA 数据源是我的 weblogic 中内容的精确副本。

有什么想法吗?

--编辑-- 这就是我获得 EntityManager 的方式

private EntityManagerFactory emf;

    protected EntityManager getEntityManager(){
        if(emf == null){
            emf = Persistence.createEntityManagerFactory("certifications");
        }
        return emf.createEntityManager(); //This is where it fails
    }

【问题讨论】:

    标签: jpa eclipselink


    【解决方案1】:

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

    ds.getConnection(username, password);
    

    改为

    ds.getConnection();
    

    请尝试删除属性 javax.persistence.jdbc.password、javax.persistence.jdbc.user 和 javax.persistence.jdbc.driver 和 ee,如果它适合你。

    编辑:您正在使用配置为从应用程序服务器(在您的情况下为 WebLogic)使用的 EclipseLink,因为您使用 JTA DataSource 和 JNDI 查找从应用程序服务器获取 DataSource 连接。 但是您使用 EclipseLink 的方式是为了在非 Java EE 环境中使用,例如独立的 JavaSE 客户端(请参阅here)。

    如果您在某处需要 EntityManager,请让 WebLogic 进行初始化,例如在 Servlet 中它看起来像这样:

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

    【讨论】:

    • 试过了,但没用。我添加了更多信息。谢谢!
    • 您能否从 WebLogic 控制台验证 DataSource 连接是否正常工作?可能是您在 WebLogic 数据源配置中使用了用户 'NI',并且其用户名或密码在 WebLogic 中定义不正确。
    • 不,weblogic 数据源具有完全不同的用户/密码组合。和我的persistence.xml中的一样
    猜你喜欢
    • 1970-01-01
    • 2012-02-23
    • 1970-01-01
    • 2011-12-06
    • 2012-01-16
    • 2014-12-27
    • 1970-01-01
    • 2012-11-08
    • 1970-01-01
    相关资源
    最近更新 更多