No Targets present in javax.persistence.ForeignKey

Description

The class javax.persistence.ForeignKey contains the following code:

@Target({})
@Retention(RUNTIME)
public @interface ForeignKey {

In other words: It specifies no targets. Consequently, it isn't possible to use the annotation at all. The correct code would be:

@Target({FIELD, METHOD, TYPE})
@Retention(RUNTIME)
public @interface ForeignKey {

(Copied from org.hibernate.annotations.ForeignKey.)

Workaround: Use the deprecated org.hibernate.annotations.ForeignKey.)

Environment

The exact version I am using is hibernate-jpa-2.1-api-1.0.0.Final.jar.

Activity

Show:
Brett Meyer
May 27, 2014, 5:39 PM

, actually, the annotation is correct here. Unlike org.hibernate.annotations.ForeignKey, javax.persistence.ForeignKey cannot be applied directly to a field, method, or class. Instead, it's provided purely as a nested annotation. Example:

@JoinColumn(name = "FOO_COL", foreignKey = @ForeignKey(name = "FOO_FK") )

Jochen Wiedmann
May 28, 2014, 6:07 AM

Thank you, Brett. Indeed, as it turns out, this is just a duplicate of and I'll close it as that. (If I can, that is.)

Assignee

Unassigned

Reporter

Jochen Wiedmann

Labels

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Suitable for new contributors

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Affects versions

Priority

Major
Configure