【问题标题】:Hibernate program hangs without any logsHibernate 程序挂起,没有任何日志
【发布时间】:2021-12-09 08:59:49
【问题描述】:

我正在尝试使用 hibernate/jpa 从 java 连接到内存中的 h2 数据库,但执行在一段时间后挂起,并且没有在 DB 中创建任何表或终止。这是我的 persistence.xml 文件和执行日志

    <?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"
                 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
                          http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
                 version="2.0">
        <persistence-unit name="myApp" transaction-type="RESOURCE_LOCAL">
            <provider> org.hibernate.ejb.HibernatePersistence </provider>
            <properties>
                <property name="javax.persistence.jdbc.url" value="jdbc:h2:tcp://127.0.0.1:8082/~/test"></property>
                <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"></property>
                <property name="javax.persistence.jdbc.user" value="chaitu"></property>
                <property name="javax.persistence.jdbc.password" value=""></property>
                <property name="hibernate.show_sql" value="true"></property>
                <property name="hibernate.format_sql" value="true"></property>
                <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"></property>
                <property name="hibernate.hbm2ddl.auto" value="create-drop"></property>
            </properties>
        </persistence-unit>
    </persistence>

这些是执行日志

Oct 22, 2021 11:36:33 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [name: myApp]
Oct 22, 2021 11:36:33 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate ORM core version 5.4.29.Final
Oct 22, 2021 11:36:33 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
Oct 22, 2021 11:36:33 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Oct 22, 2021 11:36:33 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [org.h2.Driver] at URL [jdbc:h2:tcp://127.0.0.1:8082/~/test]
Oct 22, 2021 11:36:33 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=chaitu, password=****}
Oct 22, 2021 11:36:33 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Oct 22, 2021 11:36:33 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)

【问题讨论】:

  • 你的代码呢?
  • 如果你想连接到 In-Memory-H2-Database,你应该为属性“javax.persistence.jdbc”使用类似于“jdbc:h2:mem:”的值.url”。有关详细信息,请参阅h2database.com/html/features.html 的连接模式。

标签: java spring hibernate jpa h2


【解决方案1】:

将您的数据库 URL 更改为 jdbc:h2:mem:test(test 是您的数据库名称),因为您使用的是内存中的 h2 数据库,mem 表示内存中的数据库。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-27
    • 2015-09-22
    • 1970-01-01
    相关资源
    最近更新 更多