hibernate error when hbm2ddl.auto set to update

Refael Ben eli :

when i set the hibernate.hbm2ddl.auto value to create i get no errors, but when i set it to update i get an error. i need to create the tables and update them so i need the value to be update. any ideas for what could go wrong?

here is the error:

15:55:19,148 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "WebService.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"WebService.war#swap\"" => "javax.persistence.PersistenceException: [PersistenceUnit: swap] Unable to build Hibernate SessionFactory Caused by: javax.persistence.PersistenceException: [PersistenceUnit: swap] Unable to build Hibernate SessionFactory Caused by: org.hibernate.exception.SQLGrammarException: Unable to build DatabaseInformation Caused by: org.h2.jdbc.JdbcSQLException: Table \"PG_CLASS\" not found; SQL statement: select relname from pg_class where relkind='S' [42102-193]"}} 15:55:19,154 INFO [org.jboss.as.server] (ServerService Thread Pool -- 37) WFLYSRV0010: Deployed "WebService.war" (runtime-name : "WebService.war") 15:55:19,155 INFO [org.jboss.as.server] (ServerService Thread Pool -- 37) WFLYSRV0010: Deployed "test.war" (runtime-name : "test.war") 15:55:19,155 INFO [org.jboss.as.controller] (Controller Boot Thread) WFLYCTL0183: Service status report WFLYCTL0186: Services which failed to start: service jboss.persistenceunit."WebService.war#swap": javax.persistence.PersistenceException: [PersistenceUnit: swap] Unable to build Hibernate SessionFactory

and here is my persistence xml file:

<?xml version="1.0" encoding="UTF-8"?>

http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> org.hibernate.jpa.HibernatePersistenceProvider

<class>org.Swap.WebService.Model.User</class>
<class>org.Swap.WebService.Model.BaseEntity</class>

<properties>
        <!-- Hibernate properties -->
        <property name="hibernate.hbm2ddl.auto" value="update"/>
        <property name="hibernate.connection.zeroDateTimeBehavior" value="convertToNull" />
        <property name="hibernate.show_sql" value="false" />
        <property name="hibernate.format_sql" value="true" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>

        <!-- Database properties -->
        <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" /> <!-- DB Driver -->
        <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://127.0.0.1:5432/swap" /> <!-- BD Mane -->
        <property name="javax.persistence.jdbc.user" value="hidden" /> <!-- DB User -->
        <property name="javax.persistence.jdbc.password" value="hidden" /> <!-- DB Password -->
    </properties>
</persistence-unit>

Edit: if i start the wildfly with

<property name="hibernate.hbm2ddl.auto" value="create"/>

then setting it up to update and publishing it will work until i restart wildfly. can it be a problem with wildfly loading?

EDIT2: here is the datasouces from my standalone xml:

 <datasources>
            <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
                <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
                <driver>h2</driver>
                <security>
                    <user-name>sa</user-name>
                    <password>sa</password>
                </security>
            </datasource>
            <datasource jta="false" jndi-name="java:jboss/datasources/swap" pool-name="swap" enabled="true" use-java-context="true">
                <connection-url>jdbc:postgresql://127.0.0.1:5432/swap?useUnicode=yes&amp;characterEncoding=UTF-8</connection-url>
                <driver>org.postgresql</driver>
                <security>
                    <user-name>postgres</user-name>
                    <password>postgres</password>
                </security>
            </datasource>
            <drivers>
                <driver name="h2" module="com.h2database.h2">
                    <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                </driver>
                <driver name="org.postgresql" module="org.postgresql">
                    <driver-class>org.postgresql.Driver</driver-class>
                    <xa-datasource-class>org.postgresql.Driver</xa-datasource-class>
                </driver>
            </drivers>
        </datasources>
przemek hertel :

The problem is about dialect and driver set.

Your hibernate uses H2 driver with Postgres dialect.

Caused by: org.h2.jdbc.JdbcSQLException:

you can see in hibernate logs, what driver and dialect it uses. Here is fragment showing how hibernate logs should look like:

INFO  [Version] - HHH000412: Hibernate Core {4.3.7.Final}
INFO  [Environment] - HHH000206: hibernate.properties not found
INFO  [Environment] - HHH000021: Bytecode provider name : javassist
INFO  [MppNamingStrategy] - using naming strategy: MppNamingStrategy
INFO  [Version] - HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
DEBUG [JdbcServicesImpl] - Driver ->
       name : H2 JDBC Driver
    version : 1.4.196 (2017-06-10)
      major : 1
      minor : 4
DEBUG [JdbcServicesImpl] - JDBC version : 4.0
INFO  [Dialect] - HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
INFO  [ASTQueryTranslatorFactory] - HHH000397: Using ASTQueryTranslatorFactory
INFO  [Version] - HV000001: Hibernate Validator 4.3.2.Final
INFO  [SchemaValidator] - HHH000229: Running schema validator

You can see in this example that hibernate uses

  • H2 JDBC Driver
  • org.hibernate.dialect.H2Dialect

In your stacktrace we can see that your hibernate uses postgres dialect (OK), but with H2 driver (bad)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=107327&siteId=1