tags:

views:

153

answers:

2

I am using the Hibernate Tools ant task to generate DDL from JPA annotated entities. With hibernate annotations you can name the foreign key using

@JoinColumn(name = "foo")
@org.hibernate.annotations.ForeignKey(name = "fk_foo")

Is there a pure JPA way of achiving the same?

+1  A: 

Not in annotation. You can however set the columnDefinition and write the foreign key in there.

David Rabinowitz
Worth noting that not all RDBMS accept names of the "FK" in the CREATE TABLE statement under column/constraint definition, and also that since this JPA text component is undefined in terms of its content, you cannot rely on the result from different JPA implementations
DataNucleus
Depend on your implementation and target database, it can be useful. Personally I think that it should be defined in the JPA standard, but I try to be pragmatic and play with the cards I have...
David Rabinowitz
+1  A: 

No. JDO is the only persistence specification allowing definition of FK names, onUpdate/onDelete actions etc. JPA (even in JPA2) simply doesn't go there.

--Andy (DataNucleus)

DataNucleus