We are using hibernate + DB2 in our project with hbm2ddl.auto=update. Hibernate auto creates the Primary and foreign key constraints for the first schema(i.e. when there is no schema having this set table definitions and constraints), but when we try to create the tables under new schema. It creates the table and primary keys without any issues but not the foreign keys.
When looking at the hibernate logs. it scans the tables under my first schema before creating the new tables and generates the DLL only for table creation, but not for the foreign key constraints.
My first schema name is FEB201623
Second Schema name is FEB2016231
DB2 Version : 10.5 Hibernate : 3.6
Code:
[INFO] 23 Feb 10:39:54.030 AM localhost-startStop-1 [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - table not found: APPLICATION_SPECIFIC_LABEL
......
[INFO] 23 Feb 10:39:55.400 AM localhost-startStop-1 [org.hibernate.tool.hbm2ddl.TableMetadata] - table found: FEB201623.APPLICATION_SPECIFIC_LABEL
[INFO] 23 Feb 10:39:55.400 AM localhost-startStop-1 [org.hibernate.tool.hbm2ddl.TableMetadata] - columns: [last_change, sell_by_date_text_no, label_type, tlu4_font, best_before_date_offset, storage_temperature, font_ingredients, packing_date_text_type, packing_date_text_no, barcode_no, company_text_no, tlu3_font, sell_by_date_offset_unit, fixed_weight, tlu1_font, advertising_text_type, application_type, best_before_date_offset_unit, vario_label_template, sell_by_date_offset, packing_date_format, advertising_text_no, tlu2_font, best_before_date_text_no, label_template, best_before_date_format, best_before_date_text_type, sell_by_date_text_type, automatic_date, company_text_type, sell_by_date_format]
[INFO] 23 Feb 10:39:55.400 AM localhost-startStop-1 [org.hibernate.tool.hbm2ddl.TableMetadata] - foreign keys: [fka7a8e476449719a7, fka7a8e476e6b86d78, fka7a8e47658874ac5, fka7a8e47696fbb171, fka7a8e476751d0167, fka7a8e47625636019]
[INFO] 23 Feb 10:39:55.400 AM localhost-startStop-1 [org.hibernate.tool.hbm2ddl.TableMetadata] - indexes: [sql160223101541390]
......
[DEBUG] 23 Feb 10:40:02.880 AM localhost-startStop-1 [org.hibernate.tool.hbm2ddl.SchemaUpdate] - create table FEB2016231.APPLICATION_SPECIFIC_LABEL (APPLICATION_TYPE smallint not null, LABEL_TYPE smallint not null, PACKING_DATE_TEXT_NO integer, PACKING_DATE_TEXT_TYPE smallint, BARCODE_NO smallint, ADVERTISING_TEXT_NO integer, ADVERTISING_TEXT_TYPE smallint, BEST_BEFORE_DATE_TEXT_NO integer, BEST_BEFORE_DATE_TEXT_TYPE smallint, COMPANY_TEXT_NO integer, COMPANY_TEXT_TYPE smallint, SELL_BY_DATE_TEXT_NO integer, SELL_BY_DATE_TEXT_TYPE smallint, LABEL_TEMPLATE varchar(300), VARIO_LABEL_TEMPLATE varchar(300), TLU1_FONT smallint, TLU2_FONT smallint, TLU3_FONT smallint, TLU4_FONT smallint, FONT_INGREDIENTS smallint, SELL_BY_DATE_FORMAT varchar(50), BEST_BEFORE_DATE_FORMAT varchar(50), PACKING_DATE_FORMAT varchar(50), SELL_BY_DATE_OFFSET smallint, BEST_BEFORE_DATE_OFFSET smallint, SELL_BY_DATE_OFFSET_UNIT smallint, BEST_BEFORE_DATE_OFFSET_UNIT smallint, FIXED_WEIGHT integer, AUTOMATIC_DATE smallint, STORAGE_TEMPERATURE smallint, LAST_CHANGE timestamp, primary key (APPLICATION_TYPE, LABEL_TYPE))
.......
[INFO] 23 Feb 10:40:09.301 AM localhost-startStop-1 [org.hibernate.tool.hbm2ddl.SchemaUpdate] - schema update complete
Is this hibernate default behavior? I dont want to use hbm2ddl.auto=create/create-drop.
Someone please help us on this issue.