Hi Mike,
The spec says that access type of an "Id Class" is determined by the
entity that uses it. What happens when an "Id Class" is used in two
different entities with different access type? Is this allowed? In such
a case, is it required that all the fields of the "Id Class" must have
corresponding getters & setters? I think, it *must*, otherwise, equals()
and hashcode() can not be correctly implemented. To give an example, is
the following example correct?
public class UserName implements Serializable {
public int id;
public String initial;
public int getId(){return id;}
public void setId(int id){this.id = id;}
// no getter/setter for initial, so this class has only one property
called id.
}
@IdClass(UserName.class)
@Entity public class UserCredential {
@Id int id;
@Id String initial;
String password;
}
@IdClass(UserName.class)
@Entity public class Employee {
private int id;
private String initial;
private String name;
@Id public int getId() { return id; }
public void setId(int id) { this.id = id; }
// this is not annotated as @Id.
public String getInitial() { return initial; }
public void setInitial(String initial) { this.initial = initial; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}
Thanks,
Sahoo