-->
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.  [ 8 posts ] 
Author Message
 Post subject: migrating from hibernate 4 to 5 recreate foreign keys
PostPosted: Mon Feb 22, 2016 11:52 pm 
Newbie

Joined: Mon Feb 22, 2016 11:35 pm
Posts: 4
I'm currently migrating my ejb-jar from hibernate 4 (jboss AS 7) to hibernate 5 on wildfly 10.

I've set hibernate.hbm2ddl.auto to update in our persistence.xml and hibernate.dialect to MySQL5InnoDB and when i start wildfly 10. It stays at Running hbm2ddl schema update as shown below
Code:
12:38:47,651 INFO  [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 61) HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
12:38:47,707 INFO  [org.hibernate.envers.boot.internal.EnversServiceImpl] (ServerService Thread Pool -- 61) Envers integration enabled? : true
12:38:47,884 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 60) WFLYCLINF0002: Started client-mappings cache from ejb container
12:38:49,361 INFO  [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 61) HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect
12:38:55,981 INFO  [org.hibernate.tool.hbm2ddl.SchemaUpdate] (ServerService Thread Pool -- 61) HHH000228: Running hbm2ddl schema update


At this point i can see that it recreate the indexes and foreign key for each entity.
The table already exists in the database with the foreign keys and indexes already.

Why is it recreating the foreign keys and indexes?
Also it looks like it is changing my specifed dialect. First i see HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect then a few lines later i get HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect.

Any ideas?


Top
 Profile  
 
 Post subject: Re: migrating from hibernate 4 to 5 recreate foreign keys
PostPosted: Tue Feb 23, 2016 6:26 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
The implicit naming strategy has changed according to the JPA specifications.

You could try to set the "hibernate.implicit_naming_strategy" configuration property to "legacy-hbm" which is how it worked in Hibernate 4.

As for the dialect log message, that's generated when the dialect object is instantiated. Maybe there are multiple persistence.xml discovered at runtime and one contains the HSQLDialect too. I think you need to add a breakpoint there and see what AS config is causing you this issue.


Top
 Profile  
 
 Post subject: Re: migrating from hibernate 4 to 5 recreate foreign keys
PostPosted: Wed Feb 24, 2016 6:27 pm 
Newbie

Joined: Mon Feb 22, 2016 11:35 pm
Posts: 4
Thanks for the tip,

After some testing i have figured out that the Foreign key name between hibernate 4 and 5 are different.
hibernate 4 uses "FK_<some hash>
while
hibernate 5 uses "FK<some other hash>.

It also looks like when hibernate does the schema generation hibernate 4 checks for existing foreign keys and indexes as when i use hibernate 4 over a hibernate 5 generated database i didn't get any FK_<some hash> foreign keys or indexes generated in my database as i expected.

Where as when i ran hibernate 5 over a hibernate 4 generated database interesting i got FK<some other hash> foreign keys generated but no extra indexes.
So i ended up with extra Foreign key contraints as shown below

Code:
CREATE TABLE `OP_ACCESS_TOKEN` (
  `OBJECT_ID` bigint(20) NOT NULL,
  `MODIFIED_BY` varchar(31) NOT NULL,
  `MODIFIED_DATE` datetime NOT NULL,
  `REC_STATUS` varchar(1) NOT NULL,
  `CONSUMER_KEY` varchar(64) NOT NULL,
  `CONSUMER_SECRET` varchar(64) NOT NULL,
  `AGENCY_ID` bigint(20) NOT NULL,
  `SERVICE_PROVIDER_ID` bigint(20) NOT NULL,
  PRIMARY KEY (`OBJECT_ID`),
  KEY `FK_e45y19tatyq1jxttxw7gne8c9` (`AGENCY_ID`),
  KEY `FK_oy2qxqkloypnv1x37m4hb3qiw` (`SERVICE_PROVIDER_ID`),
  CONSTRAINT `FKgkgpjour1g05greiw7x0x6xkm` FOREIGN KEY (`SERVICE_PROVIDER_ID`) REFERENCES `OP_SERVICE_PROVIDER` (`OBJECT_ID`),
  CONSTRAINT `FK58gxc0d3nlgdfiodvenu1fmao` FOREIGN KEY (`AGENCY_ID`) REFERENCES `OP_AGENCY` (`OBJECT_ID`),
  CONSTRAINT `FK_e45y19tatyq1jxttxw7gne8c9` FOREIGN KEY (`AGENCY_ID`) REFERENCES `OP_AGENCY` (`OBJECT_ID`),
  CONSTRAINT `FK_oy2qxqkloypnv1x37m4hb3qiw` FOREIGN KEY (`SERVICE_PROVIDER_ID`) REFERENCES `OP_SERVICE_PROVIDER` (`OBJECT_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


it looks like hibernate 5 does a name check instead of a key contraint check when determining to create Foreign keys.
Does this sound right?
i guess i should rename our FK and indexes


Top
 Profile  
 
 Post subject: Re: migrating from hibernate 4 to 5 recreate foreign keys
PostPosted: Thu Feb 25, 2016 1:07 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Does this happen even when you use the legacy_hbm naming strategy?


Top
 Profile  
 
 Post subject: Re: migrating from hibernate 4 to 5 recreate foreign keys
PostPosted: Thu Feb 25, 2016 4:58 pm 
Newbie

Joined: Mon Feb 22, 2016 11:35 pm
Posts: 4
Yes the same thing happen with legacy_hbm.

the ImplicitNamingStrategyLegacyHbmImpl and ImplicitNamingStrategyLegacyJpaImpl don't implement determineForeignKeyName. They use the method in ImplicitNamingStrategyJpaCompliantImpl.


Top
 Profile  
 
 Post subject: Re: migrating from hibernate 4 to 5 recreate foreign keys
PostPosted: Fri Feb 26, 2016 1:49 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You can open a JIRA issue for which you can attach a replicating test case.


Top
 Profile  
 
 Post subject: Re: migrating from hibernate 4 to 5 recreate foreign keys
PostPosted: Sun Feb 28, 2016 7:25 pm 
Newbie

Joined: Mon Feb 22, 2016 11:35 pm
Posts: 4
I've created a jira issue
its https://hibernate.atlassian.net/browse/HHH-10574


Top
 Profile  
 
 Post subject: Re: migrating from hibernate 4 to 5 recreate foreign keys
PostPosted: Mon Feb 29, 2016 11:13 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Thanks for taking your time.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.