【问题标题】:Websphere Initial SessionFactory creation failed.org.hibernate.HibernateException: Could not find datasourceWebsphere Initial SessionFactory 创建 failed.org.hibernate.HibernateException: 找不到数据源
【发布时间】:2014-10-02 12:34:59
【问题描述】:

您好,我正在尝试将我的应用程序连接到 Websphere 中定义的数据源;当我在 Websphere 中执行“测试连接”时,数据源运行良好。但是当我尝试与应用程序连接时,我在日志中遇到了这个问题:

java org.apache.openjpa.lib.conf.ProductDerivations [8/8/14 16:19:09:520 CST] 00000018 SystemErr R com.ibm.ws.persistence.WsJpaProductDerivation:java.lang.ClassNotFoundException: com.ibm.ws.persistence.WsJpaProductDerivation [8/8/14 16:23:15:269 CST] 0000002c SystemErr R Initial SessionFactory 创建 failed.org.hibernate.HibernateException:找不到数据源

这里我添加了hibernate.cfg.xml:

<hibernate-configuration>
  <session-factory>
    <property name="hibernate.connection.datasource">java:comp/env/jdbc/cmsPrueba</property>

    <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
    <property name="use_outer_join">true</property> 
    <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>                                     


    <property name="hibernate.show_sql">false</property>

    <!-- Mapping Files -->

    <mapping resource="sisa/cms/db/mapping/CmsFaq.hbm.xml"/>

在 websphere 中,我用这个 JNDI 定义了数据源:“jdbc/cmsPrueba”;我尝试了这种形式:

java:comp/env/jdbc/cmsPrueba

还有这个:

jdbc/cmsPrueba

我正在使用:

  • Websphere 7
  • 休眠 2
  • JDK 6

这是 web.xml:

<display-name>Sisa Admin Panel</display-name>
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>
<context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</param-value>
</context-param>
<context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
</context-param>
<context-param>
    <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
    <param-value>com.sun.facelets.FaceletViewHandler</param-value>
</context-param>
<context-param>
    <param-name>javax.faces.DISABLE_FACELET_JSF_VIEWHANDLER</param-name>
    <param-value>true</param-value>
</context-param>
<context-param>
    <param-name>org.ajax4jsf.handleViewExpiredOnClient</param-name>
    <param-value>true</param-value>
</context-param>
<filter>
    <display-name>RichFaces Filter</display-name>
    <filter-name>richfaces</filter-name>
    <filter-class>org.ajax4jsf.Filter</filter-class>
    <init-param>
        <param-name>createTempFiles</param-name>
        <param-value>false</param-value>
    </init-param>
    <init-param>
        <param-name>maxRequestSize</param-name>
        <param-value>40000000</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>richfaces</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<filter>
    <filter-name>HibernateFilter</filter-name>
    <filter-class>sisa.cms.admin.util.HibernateThreadFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>HibernateFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.rface</url-pattern>
</servlet-mapping>
<servlet>
    <servlet-name>imageServlet</servlet-name>
    <servlet-class>sisa.resources.ImageServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>imageServlet</servlet-name>
    <url-pattern>/image/*</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>index.jspx</welcome-file>
    <welcome-file>index.jsf</welcome-file>
    <welcome-file>default.jspx</welcome-file>
    <welcome-file>default.jsf</welcome-file>
</welcome-file-list>
<security-role>
    <description/>
    <role-name>ADMIN</role-name>
</security-role>
<security-role>
    <description/>
    <role-name>APROBADOR</role-name>
</security-role>
<security-role>
    <description/>
    <role-name>EDITOR</role-name>
</security-role>


<error-page>
    <error-code>403</error-code>
    <location>/error.html</location>
</error-page>
<error-page>
    <error-code>404</error-code>
    <location>/error-404.html</location>
</error-page>

提前致谢。

【问题讨论】:

  • 您是否在任何地方使用 JPA 注释?

标签: hibernate datasource websphere-7


【解决方案1】:

尝试像这样将资源引用添加到您的 web.xml:

<resource-ref>
      <res-ref-name>jdbc/cmsPrueba</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      <res-sharing-scope>Unshareable</res-sharing-scope>
</resource-ref>

在 WebSphere 中使用 JNDI 名称定义数据源:jdbc/cmsPrueba

您需要在安装期间或通过ibm-web-bnd.xml 文件将此资源引用绑定到JNDI 名称。如果你想使用绑定文件,只需添加以下行:

<resource-ref name="jdbc/cmsPrueba" binding-name="jdbc/cmsPrueba" />

【讨论】:

  • 非常感谢 Gas:我创建了文件 ibm-web-bnd.xml。现在我在浏览器中出现此错误:错误 500: com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource 与javax.sql.DataSource。并且日志找不到 DS: Initial SessionFactory creation failed.org.hibernate.HibernateException: Could not find datasource
  • 这可能与类加载器问题有关。确保您的 WEB-INF/lib 文件夹中没有数据库驱动程序 jar,或服务器提供的其他与 jee 相关的 jar。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-23
  • 1970-01-01
  • 2019-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多