首页 > 解决方案 > HHH10001002:使用 Hibernate 内置连接池(不用于生产!)

问题描述

在部署我的应用程序时,我收到了这个休眠警告(两次):

WARN  org.hibernate.orm.connections.pooling - HHH10001002: Using Hibernate built-in connection pool (not for production use!)

我不想使用 Hibernate 中的这些内置连接池,也不想使用 C3PO 之类的任何其他实现。

我尝试了很多东西,但我无法使用我的 Weblogic应用程序服务器的连接池。

我的persistence.xml:

<persistence...
<persistence-unit name="MY-PERSISTENCE-UNIT">
    <description>Hibernate JPA Configuration</description>
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

    <class>some classes...</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>

    <properties>
        <property name="hibernate.connection.datasource" value="jdbc/myDS"/>
        <property name="hibernate.hbm2ddl.auto" value="none"/>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle12cDialect"/>
        <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="jndi.class" value="weblogic.jndi.WLInitialContextFactory"/>
    </properties>
</persistence-unit>
</persistence>

weblogic.xml:

    ...
    <resource-description>
        <res-ref-name>jdbc/myDS</res-ref-name>
        <jndi-name>myDS</jndi-name>
    </resource-description>
    ...

网页.xml:

...
    <resource-ref>
       <res-ref-name>jdbc/myDS</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
    </resource-ref>
...

PS:我通过 Entitymanager 获得连接,但我没有任何 context.xml。

我能做些什么?有人可以帮忙吗?

标签: javahibernatejpaconnection-poolingweblogic12c

解决方案


您不应该使用属性设置数据源。<jta-data-source>使用元素将数据源提供给实体管理器有标准的方法。

你只需要这样的东西:

<persistence...
<persistence-unit name="MY-PERSISTENCE-UNIT">
    <description>Hibernate JPA Configuration</description>
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

    <jta-data-source>jdbc/myDS</jta-data-source>    

    <class>some classes...</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>

    <properties>
        <property name="hibernate.hbm2ddl.auto" value="none"/>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle12cDialect"/>
    </properties>
</persistence-unit>
</persistence>

推荐阅读