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
Hibernate Access数据源导致传递了异常Null UserID,无法创建连接_Hibernate_Jpa_Nullpointerexception_Datasource_Websphere 7 - Fatal编程技术网

Hibernate Access数据源导致传递了异常Null UserID,无法创建连接

Hibernate Access数据源导致传递了异常Null UserID,无法创建连接,hibernate,jpa,nullpointerexception,datasource,websphere-7,Hibernate,Jpa,Nullpointerexception,Datasource,Websphere 7,我已经在这个问题上工作了好几天了,还没有解决。我希望把我的问题贴在这里能指引我正确的方向。我浏览了许多论坛,所有论坛都说明了我遵循的相同步骤(如下所述),但我在访问数据源时仍然遇到相同的运行时异常 Exception - org.hibernate.exception.SQLGrammarException: Could not open connection at org.hibernate.exception.internal.SQLStateConversionDelegate.conv

我已经在这个问题上工作了好几天了,还没有解决。我希望把我的问题贴在这里能指引我正确的方向。我浏览了许多论坛,所有论坛都说明了我遵循的相同步骤(如下所述),但我在访问数据源时仍然遇到相同的运行时异常

Exception - 
org.hibernate.exception.SQLGrammarException: Could not open connection
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:122)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
Caused by: java.sql.SQLNonTransientException: [jcc][t4][10205][11234][4.11.88] Null userid is not supported. ERRORCODE=-4461, SQLSTATE=42815 DSRA0010E: SQL-Status = 42815, Fehlercode = -4'461
at com.ibm.db2.jcc.am.gd.a(gd.java:676)
环境-Hibernate、JPA2.0、DB2、WebSphere8.0、RAD、JavaEE6部署网

  • 在webspherejdbc/Sample上创建了一个数据源。在数据源上使用DB凭据创建J2C身份验证。通过容器管理的AuthenitAction将身份验证分配给数据源

  • Web.xml条目

    resource-ref
    res-ref-name Sample
    res-type javax.sql.DataSource
    res-auth Container
    res-sharing-scope Shareable
    resource-ref
    
  • Ibm-web-bnd.xml条目

    resource-ref name="jdbc/Sample" binding-name="java:comp/env/jdbc/Sample" 
    
  • Persistence.xml

    persistence-unit name="samplePool" transaction-type="JTA"
    provider org.hibernate.ejb.HibernatePersistence
    jta-data-source jdbc/Sample
    properties
    property name="hibernate.transaction.manager_lookup_class"         value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup"
    property name="hibernate.dialect" value="org.hibernate.dialect.DB2390Dialect"
    properties
    persistence-unit
    persistence
    
  • Dao中的代码

     eMgrFactory = Persistence.createEntityManagerFactory("samplePool");
     entityMgr = eMgrFactory.createEntityManager();
     entityMgr.createNativeQuery();
    

  • 请注意,通过管理控制台创建数据源后,我能够成功测试连接。另外请注意,如果我指定组件管理的身份验证,我可以通过代码访问。建议如何通过容器管理的身份验证进行访问。

    部署后,必须将数据源映射到应用程序


    .

    今天,我能够为我的问题找到解决方案。整个问题最终证明是一个配置问题。很好,我能解决。 以下是我所做的更改

  • persistence.xml文件-我不再从这里直接查找数据源。我像这样在web.xml上查找(java:comp/env/jdbc/ds)
  • xml version=“1.0”encoding=“UTF-8” 持久性xmlns=”http://java.sun.com/xml/ns/persistence“xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance“version=“2.0”xsi:schemaLocation=”http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" 持久化单元名称=“数据池”事务类型=“JTA” 提供者org.hibernate.ejb.HibernatePersistence提供者 jta数据源java:comp/env/jdbc/ds jta数据源 共享缓存模式所有共享缓存模式 性质 property name=“hibernate.dialogue”value=“org.hibernate.dialogue.db2390dialogue” property name=“hibernate.default\u schema”value=“A11” property name=“hibernate.transaction.manager\u lookup\u class”value=“org.hibernate.transaction.WebSphereExtendedJTATransactionLookup” property name=“hibernate.transaction.jta.platform”value=“org.hibernate.service.jta.platform.internal.websphereextendedjttaplatform” property name=“hibernate.temp.use\u jdbc\u metadata\u defaults”value=“false” 性质 持久性单位 坚持不懈
  • 在Web.xml中,我查找数据源
  • 资源引用 res ref name jdbc/ds res ref name 查找名称实际数据源查找名称 res type javax.sql.DataSource res type res auth容器res auth res共享作用域可共享res共享作用域 资源引用
    我为其他人发布了解决方案。

    我尝试了参考资料部分。这没有帮助。对我来说,部署描述符应该负责配置设置。欢迎提出进一步建议。你好,卡里安。 xml version="1.0" encoding="UTF-8" persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" persistence-unit name="dataPool" transaction-type="JTA" provider org.hibernate.ejb.HibernatePersistence provider jta-data-source java:comp/env/jdbc/ds jta-data-source shared-cache-mode ALL shared-cache-mode properties property name="hibernate.dialect" value="org.hibernate.dialect.DB2390Dialect" property name="hibernate.default_schema" value="A11" property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup" property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform" property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" properties persistence-unit persistence resource-ref res-ref-name jdbc/ds res-ref-name lookup-name ACTUAL DATASOURCE lookup-name res-type javax.sql.DataSource res-type res-auth Container res-auth res-sharing-scope Shareable res-sharing-scope resource-ref