hello, discuss the style of composite key by @IdClass. take the Category as example. this class use the name and createDate as comp. key. the entity part looks like:
@Entity
@IdClass(CategoryPK.class)
public class Category {
public Category() {}
@Id
protected String name;
@Id
protected Date createDate;
public String getName(){.............}
public Date getCreateDate(){..............}
public void setName(){.............}
public void setCreateDate(){.........}
}
but somebody add the @Id on getter method like:
@Entity
@IdClass(CategoryPK.class)
public class Category {
public Category() {}
protected String name;
protected Date createDate;
@Id
public String getName(){return this.name}
@Id
public Date getCreateDate(){return this.createDate}
public void setName(){.............}
public void setCreateDate(){.........}
}
it seem like both work after trying. but i have referred to at least three books, all of them just mention the first style. one of book even emphasize we must add the @id on the properties. so i am confused what's the different between them, and why the second style is not mentioned?
Thanks