Reputation: 3854
I am using Hibernate 3 with Oracle 10.
Is there a way to specify in a Hibernate mapping file the constraint names (from foreign keys, unique constraints, etc) that will be created rather than the (not user-friendly) generated ones?
Upvotes: 2
Views: 3279
Reputation: 1990
Yes, with recent versions of Hibernate (at least 3.5+) you can use the @ForeignKey annotation.
http://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/annotations/ForeignKey.html
Upvotes: 2
Reputation: 13734
I've used the unique-key="name of constraint" syntax successfully with Oracle before. There is also a property called foreign-key on many-to-one that I assume does the same thing (although the documentation doesn't say).
For example, I know this works for unique constraints:
<many-to-one name="column1" class="Class1" unique-key="TABLE_U1"/>
<property name="column2" unique-key="TABLE_U1" />
I assume this would work for the foreign key:
<many-to-one name="column1" class="Class1" foreign-key="TABLE_FK1"/>
Upvotes: 1