I am looking for a way to have a typesafe primary key for my entities using generics in Hibernate. Instead of doing this
@Entity
public class User{
@PrimaryKey
Long id
}
I was thinking of doing this...
@Entity
public class User{
@PrimaryKey
PrimaryKey<User,Long> id
}
Or take the type inference even further...
Any ideas? Has anybody ever tried this before? Would you do this by making your class PrimaryKey embeddable?
@Entity
public class User extends MyEntity<Long>//Primary key type{
@PrimaryKey
PrimaryKey<User> id;
}