Generic Generator parameters in Hibernate cannot be set

annotations, foreign-keys, hibernate, one-to-one

Solution

You're using `javax.persistence.Parameter` instead of using `org.hibernate.annotations.Parameter`.

Importing all classes from a package is generally considered as a bad practice. Only import the classes that you need.

Problem

I want to use foreign strategy generator for one of key properties in my class. The easiest way as shown in: http://blog.eyallupu.com/2011/01/hibernatejpa-identity-generators.html or http://www.coderanch.com/t/219256/ORM/databases/HBM-Annotation-Foreign-Generator or http://www.mkyong.com/hibernate/hibernate-one-to-one-relationship-example-annotation/ ``` import java.util.Date; import java.util.HashSet; import java.util.Set; import javax.persistence.*; import org.hibernate.annotations.GenericGenerator; ... ... ... @GenericGenerator( name = "myForeignGenerator", strategy = "foreign", parameters = @Parameter(name = "property", value = "osoba")) @Id @GeneratedValue(generator = "myForeignGenerator") @Column(name = "IdPracownik", unique = true, nullable = false) public int getIdPracownik() { return this.idPracownik; } ``` and Eclipse shows error: "Type mismatch: cannot convert from Parameter to Annotation", underlining "@Parameter" annotation. Why is that?

Original source