-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate not creating foreign key constraints in DB2
PostPosted: Thu Mar 17, 2016 6:27 am 
Newbie

Joined: Thu Mar 17, 2016 6:22 am
Posts: 1
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.


Top
 Profile  
 
 Post subject: Re: Hibernate not creating foreign key constraints in DB2
PostPosted: Thu Mar 17, 2016 7:56 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
We are using hbmddl during testing and FK are created for other DBs. If this is a DB2 issue, please attach a replicating test case to a Jira issue.

I would not use hbmddl on a production database because a tool like FlywayDB allows you to gain more control over the underlying schema changes.
Hbmddl is more useful for testing.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.