Websphere初始SessionFactory创建failed.org.hibernate.HibernateException:找不到数据源

时间:2014-08-08 23:06:56

标签: hibernate datasource websphere-7

您好我试图将我的应用程序连接到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初始SessionFactory创建失败..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定义了数据源:&#34; jdbc / cmsPrueba&#34 ;;我尝试了这种形式:

的java:comp / env的/ JDBC / cmsPrueba

和这一个:

JDBC / cmsPrueba

我正在使用:

  • Websphere 7
  • Hibernate 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>

提前致谢。

1 个答案:

答案 0 :(得分:0)

尝试向您的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" />