property "hibernate.hbm2ddl.auto" value="update" is not working with postgres

1

The persistence.xml: configuration property

 property name="hibernate.hbm2ddl.auto" value="update"

It is not working or better this is giving error at the time of deploy. If used as create works but even in development getting erased the base every time I create a new entity in the project is costing me a lot of time. If retreating the property also works.

property name="hibernate.hbm2ddl.auto" value="create"

I'm using the Database:

Postgres 9.4.8  
WildFly 10.  
Hibernate 5.2.0.Final

Configuring properties.xml

<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="use_sql_comments" value="true" /> 
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL94Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>

Error occurring:

>08:22:22,751 ERROR [org.jboss.msc.service.fail] (ServerService Thread
> Pool -- 59) MSC000001: Failed to start service
> jboss.persistenceunit."perolawebsecurityadmin.war#PEROLAWEB":
> org.jboss.msc.service.StartException in service
> jboss.persistenceunit."perolawebsecurityadmin.war#PEROLAWEB":
> javax.persistence.PersistenceException: [PersistenceUnit: PEROLAWEB]
> Unable to build Hibernate SessionFactory  at
> org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172)
>   at
> org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117)
>   at
> org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:667)
>   at
> org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182)
>   at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>   at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>   at java.lang.Thread.run(Thread.java:745)    at
> org.jboss.threads.JBossThread.run(JBossThread.java:320) Caused by:
> javax.persistence.PersistenceException: [PersistenceUnit: PEROLAWEB]
> Unable to build Hibernate SessionFactory  at
> org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954)
>   at
> org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:882)
>   at
> org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
>   at
> org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154)
>   ... 7 more Caused by: org.hibernate.exception.SQLGrammarException:
> Error creating DatabaseInformation for schema migration   at
> org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:106)
>   at
> org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
>   at
> org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
>   at
> org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95)
>   at
> org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:127)
>   at
> org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:101)
>   at
> org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:470)
>   at
> org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
>   at
> org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
>   ... 9 more Caused by: org.h2.jdbc.JdbcSQLException: Table "PG_CLASS"
> not found; SQL statement: select relname from pg_class where
> relkind='S' [42102-173]   at
> org.h2.message.DbException.getJdbcSQLException(DbException.java:331)
>   at org.h2.message.DbException.get(DbException.java:171)     at
> org.h2.message.DbException.get(DbException.java:148)  at
> org.h2.command.Parser.readTableOrView(Parser.java:4864)   at
> org.h2.command.Parser.readTableFilter(Parser.java:1107)   at
> org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:1713)     at
> org.h2.command.Parser.parseSelectSimple(Parser.java:1821)     at
> org.h2.command.Parser.parseSelectSub(Parser.java:1707)    at
> org.h2.command.Parser.parseSelectUnion(Parser.java:1550)  at
> org.h2.command.Parser.parseSelect(Parser.java:1538)   at
> org.h2.command.Parser.parsePrepared(Parser.java:405)  at
> org.h2.command.Parser.parse(Parser.java:279)  at
> org.h2.command.Parser.parse(Parser.java:251)  at
> org.h2.command.Parser.prepareCommand(Parser.java:218)     at
> org.h2.engine.Session.prepareLocal(Session.java:428)  at
> org.h2.engine.Session.prepareCommand(Session.java:377)    at
> org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1138)
>   at org.h2.jdbc.JdbcStatement.executeQuery(JdbcStatement.java:72)    at
> org.jboss.jca.adapters.jdbc.WrappedStatement.executeQuery(WrappedStatement.java:397)
>   at
> org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl.extractMetadata(SequenceInformationExtractorLegacyImpl.java:42)
>   at
> org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl.initializeSequences(DatabaseInformationImpl.java:64)
>   at
> org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl.<init>(DatabaseInformationImpl.java:60)
>   at
> org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:123)
>   ... 13 more
> 
> 08:22:22,757 ERROR [org.jboss.as.controller.management-operation]
> (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed -
> address: ([("deployment" => "perolawebsecurityadmin.war")]) - failure
> description: {"WFLYCTL0080: Failed services" =>
> {"jboss.persistenceunit.\"perolawebsecurityadmin.war#PEROLAWEB\"" =>
> "org.jboss.msc.service.StartException in service
> jboss.persistenceunit.\"perolawebsecurityadmin.war#PEROLAWEB\":
> javax.persistence.PersistenceException: [PersistenceUnit: PEROLAWEB]
> Unable to build Hibernate SessionFactory
>     Caused by: javax.persistence.PersistenceException: [PersistenceUnit: PEROLAWEB] Unable to build Hibernate SessionFactory
>     Caused by: org.hibernate.exception.SQLGrammarException: Error creating DatabaseInformation for schema migration
>     Caused by: org.h2.jdbc.JdbcSQLException: Table \"PG_CLASS\" not found; SQL statement:
    
asked by anonymous 29.06.2016 / 13:45

1 answer

0

Checks the permissions of the user that you have set up in persistence.xml. The error is complaining of the impossibility of finding a standard postgres table, the pg_class that belongs to the postgres user. This way, the user configured in your persistence.xml must have select permission on that table. To do this, the simplest way to grant permission is to put it as supersuser in the database. An example script for creating a user like this would be:

CREATE ROLE usuario LOGIN
ENCRYPTED PASSWORD 'md5a3556571e93b0d20722ba62be61e8c2d'
SUPERUSER INHERIT CREATEDB CREATEROLE REPLICATION;
    
06.09.2016 / 02:42