Session bean to generate primary key for entity bean.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Farida_Shameem
Posted On:   Monday, October 7, 2002 01:56 AM

I want to insert a record in the DB thru entity bean, generating the primary key (getting the max of the primary key field and adding 1 to it.) thru a session bean. Please let me know how can i do it.

Re: Session bean to generate primary key for entity bean.

Posted By:   jaivir_singh  
Posted On:   Monday, October 7, 2002 10:37 PM

Hi Farida ,



Now a days there are containers that allow you to configure , such a requirement , ie for a particular entity bean you can provide details like which sequence it has to use and evertime ,before execution of ejbCreate container gets the lastet val for the seq and provides it to ejbCreate .One such container is WL 6.1 .We can exclude the primary key parameter in ejb create method since the caller will never supply that .




In case you are not using such a container than , the only way out is , that in your ejbCreate ,invoke a method that gets the latest val of sequence for you using normal jdbc, with a query to get next val for seq, and you use it to insert it into database .Here too we can exclude the primary key parameter in create method since the caller will never supply that .



Many a times we can have a special session bean for this purpose , where we pass tha name of the seq , and the latest val for that sew is returned.




Hope this helps you .




Cheers

Jaivir
About | Sitemap | Contact