• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Primary Key + Serializable

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic