2

我将我的应用程序迁移到 Hibernate 5 和 Glassfish 4。部署时,它尝试生成数据库,但出现此错误:

aused by: org.hibernate.tool.schema.spi.SchemaManagementException: Unable to execute schema management to JDBC target [create table banca (id int8 not null, descricao varchar(255), publica boolean not null, primary key (id))]
at org.hibernate.tool.schema.internal.TargetDatabaseImpl.accept(TargetDatabaseImpl.java:59)
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlString(SchemaMigratorImpl.java:332)
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlStrings(SchemaMigratorImpl.java:321)
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.createTable(SchemaMigratorImpl.java:142)
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigrationToTargets(SchemaMigratorImpl.java:98)
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:59)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:129)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:97)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:476)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:802)
... 47 more
Caused by: org.postgresql.util.PSQLException: ERRO: table "banca" exists
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2270)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1998)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:570)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:406)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:334)
at com.sun.gjc.spi.base.StatementWrapper.executeUpdate(StatementWrapper.java:118)
at org.hibernate.tool.schema.internal.TargetDatabaseImpl.accept(TargetDatabaseImpl.java:56)

这是真的,因为数据库中存在表“banca”,但我的 persistence.xml 是:

   <persistence-unit name="myPU" transaction-type="JTA">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <jta-data-source>jdbc/myDS</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.hbm2ddl.auto" value="update"/>
        <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
    </properties>
</persistence-unit>

[编辑] 正在使用 persistence.xml,在 Glassfish 日志中出现:

Informações:   HHH000204: Processing PersistenceUnitInfo [
name: myPU
...]
Informações:   HHH000412: Hibernate Core {5.0.0.CR2}
Informações:   HHH000206: hibernate.properties not found
Informações:   HHH000021: Bytecode provider name : javassist
Informações:   HCANN000001: Hibernate Commons Annotations {5.0.0.Final}
Informações:   HHH000400: Using dialect:             org.hibernate.dialect.PostgreSQLDialect
Informações:   HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
Informações:   HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@5e237c59
Informações:   HV000007: META-INF/validation.xml found. Parsing XML based configuration.
Informações:   HV000004: Using com.xpert.i18n.CustomInterpolator as message interpolator.
Informações:   HHH000228: Running hbm2ddl schema update
Informações:   HHH000262: Table not found: banca
[...]
4

0 回答 0