每次我想运行它时,hibernate jpa应用程序都会暂停

时间:2018-01-03 22:35:13

标签: java hibernate jpa jpa-2.1 suspend

我正在使用带有JPA 2.1 Library的Hibernate 5.2。每次我想运行我的应用程序它都不会停止 - 我必须手动停止它,因为它仍在工作。记录正在正确保存到数据库中。这些是我的项目文件:

Main.java

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
            EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("testjpa");
    EntityManager em = entityManagerFactory.createEntityManager();

    em.getTransaction().begin();
            Kraj country = new Kraj();
            country.setNazwa("ExampleCountry");
            em.persist(country);
    em.getTransaction().commit();
    em.close();

}

**

peristence.xml

**

    <?xml version="1.0" encoding="UTF-8" ?>
<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" xmlns="http://java.sun.com/xml/ns/persistence">
  <persistence-unit name="testjpa">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <class>bazafilmow.model.Aktor</class>
    <class>bazafilmow.model.Film</class>
    <class>bazafilmow.model.Gatunek</class>
    <class>bazafilmow.model.Kraj</class>
    <class>bazafilmow.model.Rezyser</class>
    <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/testdb"/>
      <property name="javax.persistence.jdbc.user" value="postgres"/>
      <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
      <property name="javax.persistence.jdbc.password" value="****"/>
      <property name="hibernate.flushMode" value="FLUSH_AUTO" />
      <property name="hibernate.hbm2ddl.auto" value="validate" />
    </properties>
  </persistence-unit>
</persistence>

输出

run:
Jan 03, 2018 11:23:06 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [
    name: testjpa
    ...]
Jan 03, 2018 11:23:06 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.12.Final}
Jan 03, 2018 11:23:06 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jan 03, 2018 11:23:06 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Jan 03, 2018 11:23:06 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Jan 03, 2018 11:23:06 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost:5432/testdb]
Jan 03, 2018 11:23:06 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=postgres, password=****}
Jan 03, 2018 11:23:06 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Jan 03, 2018 11:23:06 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Jan 03, 2018 11:23:06 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL81Dialect
Jan 03, 2018 11:23:07 PM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
Jan 03, 2018 11:23:07 PM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@45cff11c] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
Jan 03, 2018 11:23:07 PM org.hibernate.hql.internal.QueryTranslatorFactoryInitiator initiateService
INFO: HHH000397: Using ASTQueryTranslatorFactory

此时它暂停,没有BUILD SUCCESSFULL信息。

1 个答案:

答案 0 :(得分:0)

更改适用于我的版本后,我遇到了同样的问题。