java - 如何使用 JPA(即 Hibernate EntityManager)解决 "Using Hibernate built-in connection pool (not for production use!)"

标签 java hibernate jpa connection-pooling

总的来说,我对 Hibernate 和 JPA 还很陌生。

我阅读了很多有关此警告的内容,但仍然无法解决它。

到目前为止我读到的答案说项目中必须有 hibernate.cfg.xml 。 但我也读到:

If you are using JPA i.e. Hibernate EntityManager, you'll need the persistence.xml. So you generally don't need both as you use either Hibernate proprietary API or JPA. (what is the purpose of two config files for Hibernate?)

使用 persistence.xml 每次使用 Hibernate 时我都会收到此警告。

这是我的persistence.xml:

<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="integration"
        transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

        <properties>
            <property name="hibernate.dialect"
                value="org.hibernate.dialect.MySQL5InnoDBDialect" />
            <property name="hibernate.hbm2ddl.auto" value="update" />
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/db-name?autoReconnect=true"/>
            <property name="hibernate.connection.username" value="root" />
            <property name="hibernate.connection.password" value="root" />
            <property name="hibernate.show_sql" value="false" />
            <property name="hibernate.format_sql" value="true" />
            <property name="hibernate.id.new_generator_mappings"
                value="true" />
        </properties>
    </persistence-unit>

</persistence>

我不知道我做错了什么。

提前致谢

最佳答案

这只是一个警告,表明您正在使用内置连接池,这不是生产环境中合适的解决方案,您应该在生产环境中使用应用程序服务器连接池。根据您的应用程序服务器,您可以在应用程序服务器内设置数据库连接,然后配置 hibernate 以使用该连接。 但如果你想在不配置应用服务器的情况下解决这个问题你可以看this .

关于java - 如何使用 JPA(即 Hibernate EntityManager)解决 "Using Hibernate built-in connection pool (not for production use!)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58375169/

相关文章:

java - 具有大量列的 MySQL JPA 查询运行速度比预期慢得多

java - @Query 的 SELECT 子句中的参数?

java - 带有泛型的 lambda 类型检测不正确

MySQL锁等待超时和死锁错误

java - Hibernate:使用 sessionFactory.getTypeHelper().custom(userType) 时出现问题

java - 如何修复 "You have an error in your SQL syntax"JPA持久性

java - 如何从主方法(或任何方法)中的args[]初始化java中的常量,例如 "public static final Integer"

java - 无法从我的桌面连接到 ec2 上的 rabbitmq

java - hibernate 并选择连接

java - 当更新一个实体时, hibernate 尝试删除其他实体中的引用