Reputation: 53
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&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>
Upvotes: 3
Views: 1497
Reputation: 53
Thanks to przemek hertel i managed to get it to work. i remove the h2 from the datasource and driver
<datasources>
<datasource 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&characterEncoding=UTF-8</connection-url>
<driver>org.postgresql</driver>
<security>
<user-name>postgres</user-name>
<password>postgres</password>
</security>
</datasource>
<drivers>
<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>
and i removed this line:
<default-bindings context-service="java:jboss/ee/concurrency/context/default" datasource="java:jboss/datasources/ExampleDS" managed-executor-service="java:jboss/ee/concurrency/executor/default" managed-scheduled-executor-service="java:jboss/ee/concurrency/scheduler/default" managed-thread-factory="java:jboss/ee/concurrency/factory/default"/>
and now it is working! thank you all for the help.
Upvotes: 0
Reputation: 4024
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
In your stacktrace we can see that your hibernate uses postgres dialect (OK), but with H2 driver (bad)
Upvotes: 2