• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Primary Key + Serializable

 
Manish Katyan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class customerKey {
public int id;
public String name;
}

- Is this a valid primary key class definition? Shouldnt it be declared as serializable.

Please let me know.


Thx.
 
KasiMurugan Ramasamy
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Manish,

I think yours primary key class is not seems to be ok. You have to implement serializable. Because the container might be maintains the primary key objects in the secondary storage, when the corresponding EJBObjects take rest( I mean the corresponding Entity Bean instance goes to the pooled state from read state).That is my guess, iam not sure about why primary key class should implements Serializable.

Regards
Kasimurugan R.
 
Manish Katyan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was also expecting the same - primary key class should be implementing serializable interface - however in whizlabs's practise test its declared as valid declaration.

Thanks for your response.
 
sawan parihar
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EJB 1.1
A compound primary key is a class that implements Serializable and contains one or more public fields whose names and types match a subset of the container-managed fields in the bean class

In EJB 2.0 specs I believe its not necessary that the primary key class should implement Serializable.

Hope that helps.
 
Miki Muzsi
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manish,

Acording to the spec 10.6.13 the primary key must be RMI-IIOP compatible which means it must be serializable.

Besides that, the primary key class must provide valid implementation of hashCode() and equals() methods. Which means, very strictly speaking, your example of primary key does not comply with both conditions: serializable and valid implementations of hashCode() and equals().

Miki
 
Aravind Kumar
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by KasiMurugan Ramasamy:
Hi Manish,

I think yours primary key class is not seems to be ok. You have to implement serializable. Because the container might be maintains the primary key objects in the secondary storage, when the corresponding EJBObjects take rest( I mean the corresponding Entity Bean instance goes to the pooled state from read state).That is my guess, iam not sure about why primary key class should implements Serializable.

Regards
Kasimurugan R.


In the pooled state, bean instances looses its state, ie its not associated with any data. So I dont think the container would store the primary keys. It needs to be serialized because we have getPrimaryKey() method in the component interface, which means the PrimaryKey instance should be wired to the client. Hence should be serialized.
 
sawan parihar
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My previous post:
In EJB 2.0 specs I believe its not necessary that the primary key class should implement Serializable


This is wrong as PK should be serializable. Thanks guys for clarification.

sawan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic