Re: Session bean to generate primary key for entity bean.
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 .