Schema update is broken when using multiple schemas with sequences

Description

The issue occur in the last lines of org.hibernate.cfg.Configuration.generateSchemaUpdateScript() where the isSequence method return bogus values.

https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java#L1270

In DatabaseMetadata, sequences HashSet still use unqualified sequence name, so isSequence() method does not take in account sequence schema or catalog. For information, isTable() implementation is fine are manage takes in account schemas and catalogs.

https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/DatabaseMetadata.java#L193

I think DatabaseMetadata.initSequence should use identifier(catalog, schema, name) instead of just sequence name to populate the sequences Hashset, and DatabaseMetadata.isSequence logic updated accordingly.

https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/DatabaseMetadata.java#L166

Test case : if you have 2 applications application1 and application2 using each their own schema (quite common) : schema1 and schema2. They are configured with hibernate.hbm2ddl.auto=update

You start application1 with an empty database, it will work as expected, tables and sequence are created in schema1. But when you start application2, tables will be created in schema2 but not the sequence because schema1.hibernate_sequence will be processed as hibernate_sequence, so schema2.hibernate_sequence will never be created.

Activity

Steve EbersoleJuly 19, 2015 at 4:13 PM

As I mentioned before, schema migration (update) has undergone a massive face-lift in 5.0. In fact prior to 5.0 it was not really even considered "supported".

If you still see trouble with 5.0, please open a new issue with the appropriate details.

Steve EbersoleJuly 9, 2013 at 3:47 PM

Use master. The new work I talked about is on a dedicated topic branch. Master is currently 4.3 development. We can apply your change to all the necessary branches, but it is easier to start that from master.

Sébastien DeleuzeJuly 9, 2013 at 3:42 PM

Yep I will try when I will have the time. Should I use 4.1 ou 4.2 branch ?

Steve EbersoleJuly 9, 2013 at 3:24 PM

Yes you are probably correct. Would you be willing to try your hand at fixing this and contributing? https://github.com/hibernate/hibernate-orm/blob/master/CONTRIBUTING.md

We are in the process of redoing all this low-level mapping code which is to be the basis of Hibernate 5.0. We are redoing it all because the code had quite a few design flaws (over reliance on untyped strings being one).

Sébastien DeleuzeJuly 9, 2013 at 3:07 PM

Any feedback ?

Out of Date

Details

Assignee

Reporter

Components

Affects versions

Priority

Created July 3, 2013 at 9:52 PM
Updated July 19, 2015 at 4:13 PM
Resolved July 19, 2015 at 4:13 PM