-->
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.  [ 3 posts ] 
Author Message
 Post subject: DDLs generated by H4 not fully compatible with H5
PostPosted: Mon Oct 17, 2016 10:19 am 
Newbie

Joined: Mon Oct 17, 2016 9:59 am
Posts: 2
Hello everyone.

I am trying to make our jBPM entities to work with both Hibernate 4 (4.2.20.Final) and Hibernate 5 (5.0.9.Final). The issue I am facing right now is with DDLs generated by Hibernate 4. They work only partially when using Hibernate 5, as the foreign key has different name (it seems the algorithm which generates the name changed?). This results in Hibernate 5 creating additional FKs, identical to the ones in the DDL, but with different names.

These are the DDLs we currently use (generated by H5): https://github.com/droolsjbpm/jbpm/tree ... dl-scripts.

There seems to be a way to define the FK name via org.hibernate.annotations.ForeignKey. Is this a good idea considering the annotation is Hibernate specific? Could there be any potential issue when using different JPA 2.0 provider?

Or is there a better way to make the DDLs work for both Hibernate 4 and Hibernate 5?

Note: We do need to keep the JPA 2.0 compatibility so can't use the javax.persistence.ForeignKey (we will use that once we upgrade to H5 only).

Thanks,
Petr


Top
 Profile  
 
 Post subject: Re: DDLs generated by H4 not fully compatible with H5
PostPosted: Mon Oct 17, 2016 10:51 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Hibernate now defines several implicit naming strategies which can be defined via the
Code:
hibernate.implicit_naming_strategy
configuration property:

- default:: for org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl - an alias for jpa

- jpa:: for org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl - the JPA 2.0 compliant naming strategy

- legacy-hbm:: for org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl - compliant with the original Hibernate NamingStrategy

- legacy-jpa:: for org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl - compliant with the legacy NamingStrategy developed for JPA 1.0, which was, unfortunately, unclear in many respects regarding implicit naming rules.

However, the implicit FOREIGN KEY names are only defined in the ImplicitNamingStrategyJpaCompliantImpl.

Can you post the Hibernate 4 and the Hibernate 5 FOREIGN KEY differences to see if they could be easily resolved by the
Code:
legacy-hbm
implicit naming strategy, which was created to mimic the default naming strategy in Hibernate 4?


Top
 Profile  
 
 Post subject: Re: DDLs generated by H4 not fully compatible with H5
PostPosted: Mon Oct 17, 2016 2:43 pm 
Newbie

Joined: Mon Oct 17, 2016 9:59 am
Posts: 2
Thanks for the pointers Vlad!

So this one the FKs generated by Hibernate 4:
Code:
alter table Attachment
    add constraint FK_hqupx569krp0f0sgu9kh87513
    foreign key (TaskData_Attachments_Id)
    references Task;


and this is what I get from Hibernate 5 (using the default config):
Code:
alter table Attachment
    add constraint FKjj9psk52ifamilliyo16epwpc
    foreign key (TaskData_Attachments_Id)
    references Task;

The above is for H2 (as that's the easiest to get), but we see the same issue on other DBs as well.

I've not described this well in the first post (sorry about that), but I am actually trying to sync the constrain names, not the foreign key name (which is the same for both cases). The issue with having different name for the constraint is that H5 is then trying to crate new constraints (even though the other ones were already created directly by running the DDLs). We use hibernate.hbm2ddl.auto=update for better OOTB experience (we know this is not the recommended way in production and thus provide DDLs as well). So maybe using hibernate.hbm2ddl.auto="none" could help in this case?


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