Home > Blockchain >  Hibernate program hangs without any logs
Hibernate program hangs without any logs

Time:10-26

I am trying to connect to in memory h2 database from java using hibernate/jpa but execution is hanging after while and not creating any tables in DB or terminating either. this is my persistence.xml file and execution log

    <?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>

These are the execution logs

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)

CodePudding user response:

refer to this https://www.javatpoint.com/spring-boot-h2-database, and you will find the solution. Firstly do things as explained in the above provided link and get the required result, it worked for me.

CodePudding user response:

Change your database URL to jdbc:h2:mem:test (test is your database name) because you are using an in-memory h2 database and mem represents the in-memory database.

  • Related