0 Replies Latest reply on Sep 24, 2016 2:54 PM by skidvd1

    hibernate.hbm2ddl.auto value=“update” issue with Hibenate 3.4 to 5.1 migration

    skidvd1

      0 down vote  favorite

       

      I have an application presently running (without issue) on JBoss 6 that I am attempting to upgrade to run on WildFly 10.1. Much of this upgrade is going well. However, the upgrade from Hibernate 3.4 (on JBoss 6) to Hibernate 5.1 (on WildFly 10.1) is causing a few issues.

      Specifically, in my persistence.xml, I include the following property.

       

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

      Please NOTE: I am NOT making any schema or other DB changes as part of the upgrade. Furthermore, I am pointing at the same database instance that has been successfully running under the JBoss 6/Hibernate 3.4 instance. Therefore, I am confident that inclusion of this property should have no actual work/update to do upon first run with the WildFly 10.1/Hibernate 5.1 version.

      However, inclusion of this property appears to 1) erroneously determine that it needs to make updates and 2) fail to do so successfully. It results in the following stack trace:

       

      Failed to start service jboss.persistenceunit."app.ear#PU": org.jboss.msc.service.StartException in service jboss.persistenceunit."PU": javax.persistence.PersistenceException: [PersistenceUnit: PU] Unable to build Hibernate SessionFactory
            ...
            Caused by: javax.persistence.PersistenceException: [PersistenceUnit: PU] Unable to build Hibernate SessionFactory
            ...
            Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Unable to execute schema management to JDBC target [create index company_id_index on APPROVER (COMPANY_ID)]
            ...
            Caused by: org.postgresql.util.PSQLException: ERROR: relation "company_id_index" already exists

       

      Again, the table and index in question already exist (as confirmed by the final error).

      Is Hibernate now no longer case sensitive (COMPANY_ID_INDEX being different than company_id_index)?

      If so, how can I configure it so that it is case insensitive as it used to be (Postgres defaults all of this to lower....)

      TIA!

       

       

       

      ------

       

       

      Doh! Face palm!  I recently discovered that similar errors were also occurring related to hbm2ddl index creation with Hibernate 3.4/JBoss 6 as I am now experiencing with Hibernate 5.1/Wildfly 10.1; however, they were NOT preventing successful start up of the persistence module.  Essentially, they were being only subtly suppressed.  I'm not sure if this is an expected change related to the Hibernate versions or not, as they do prevent it's start up in Hibernate 5.1/Wildfly 10.1?

       

      The underlying issue here turned out to be that index names must be unique across the entire schema in Postgres.  So multiple entities each having a FK to a COMPANY_ID column must each have a unique name for the index.  Indices are relations in Postgres (driving the unique across schema requirement). 

       

      Thank you for the suggestions and apologies for the confusion.