persistence@glassfish.java.net

RE: Access type of id class

From: Mike Keith <michael.keith_at_oracle.com>
Date: Thu, 6 Apr 2006 15:59:31 -0400

Sahoo,

There is nothing in the spec that either requires or prohibits this kind of
dual access, so it would fall into the unspecified category.

-Mike

> -----Original Message-----
> From: Sanjeeb.Sahoo_at_Sun.COM [mailto:Sanjeeb.Sahoo_at_Sun.COM]On Behalf Of
> Sanjeeb Kumar Sahoo
> Sent: Thursday, April 06, 2006 8:27 AM
> To: Mike Keith; Ware Tom G
> Cc: Linda DeMichiel; persistence_at_glassfish.dev.java.net
> Subject: Access type of id class
>
>
> 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
>