GeeCON Prague 2014*
The moose likes EJB and other Java EE Technologies and the fly likes Session bean lifetime Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Session bean lifetime" Watch "Session bean lifetime" New topic
Author

Session bean lifetime

David Fahy
Greenhorn

Joined: Feb 13, 2004
Posts: 6
Hi,
I have a session bean that performs encryption/decryption of credit card numbers and then sends the data to an entity bean to be written to the database. When the session bean is created a key is read from the database (in ejbcreate method) and used in the encryption/decryption process. I am just wondering if the key will be present in the bean for its lifetime for each method call or will I have to read the key from the database each time I want to do encryption/decryption. Any help is appreciated.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by David Fahy:
I am just wondering if the key will be present in the bean for its lifetime for each method call or will I have to read the key from the database each time I want to do encryption/decryption. Any help is appreciated.

If you store the key in an instance member of your session bean, then *that* session bean instance will not need to hit the database again. If you store the key in a class member, then it will be available to *every* bean instance. This is the textbook case for using members in session beans.
One design enhancement would be to factor out the code that reads the key into a helper class and use that helper from the session bean. That way if more session beans or other objects need the service it will already be available.
 
GeeCON Prague 2014
 
subject: Session bean lifetime