Another issue I found with the @ForeignKey annotation: it doesn't work with 
inheritance when using InheritanceType.TABLE_PER_CLASS because this would 
generate the same foreign key name for each subclass but they must be unique in 
the database!

-----Oorspronkelijk bericht-----
Van: Henno Vermeulen [mailto:he...@huizemolenaar.nl] 
Verzonden: maandag 22 april 2013 13:28
Aan: 'users@openjpa.apache.org'
Onderwerp: repeatable autogenerate names for key constraints

When I let OpenJPA generate my database schema on sql server, the generated 
foreign keys have names such as

PK__booking___3213E83F5626D20A
FK__booking_A__ACTIV__6E886B80

When I later generate the schema again I get different names, e.g.

PK__booking___3213E83F7C97F46A
FK__booking_A__EVENT__1311456E

I use a database schema comparison tool to create a migration script for a 
newer version of my application. Because of the different names it lists very 
many changes that are not really changes at all.

Is it possible to let OpenJPA automatically generate the same names for the 
same primary/foreign keys? Perhaps it is possible to override the default 
strategy with a few lines of Java code? Is there another approach you can 
suggest?

All of my entities inherit an autogenerated primary key from a single mapped 
superclass.

PS. I know of the @ForeignKey annotation but it has a few drawbacks:

-          adds unnecessary boilerplate code (name can be autogenerated without 
numbers) that takes time to maintain.

-          Not sure if it works for mappings such as element collections and 
Maps

-          Obviously won't work for primary keys, especially not if it is 
defined in one place in a mapped superclass

Reply via email to