• 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
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Session bean lifetime

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic