EJB session bean design questions

D

davout

I'm building my first complicated EJB application and I've hit a problem to
do with declarative transaction settings. It's a subject that to date I've
been able to ignore - now I'm hoping somebody can help me with some general
guidance. I'm using the facade pattern where a stateless session bean masks
access to underlying CMP entity beans.

One of my more important session bean methods is a lengthy process that
involves multiple steps, each step will itself call one or more other
stateless session beans. Most of the calls to other stateless session beans
are to retrieve information, like 'getEntityX', 'findAllEntityY'.

Occasionally one of these retrieval calls will fail, (the underlying entity
may not exist). This is perculating up as a exception which triggers a
transaction roll back error in the main process, which is not what I want.
So it seems that I have to declare the transaction settings for each of the
retrieval related methods to avoid yes, right?

These leads to two general design questions on stateless session beans that
act as facades...

a). How to handle data not found situations.
If I have a session bean method like....

public EmployeeVO findEmployee(String anEmployeeCode);

.... what should the method return if the employee does not exist. Should I
allow a EJBException to be thrown, or should the session bean method capture
the exception and return a null value object result. Both methods are
possible, I'm just wondering what is the more popular?

b). Declarative transactions for session bean methods
Should I by default make all session bean retrieval related methods have a
'not supported' transaction setting?
 
S

Sudsy

davout wrote:
These leads to two general design questions on stateless session beans that
act as facades...

a). How to handle data not found situations.
If I have a session bean method like....

public EmployeeVO findEmployee(String anEmployeeCode);

... what should the method return if the employee does not exist. Should I
allow a EJBException to be thrown, or should the session bean method capture
the exception and return a null value object result. Both methods are
possible, I'm just wondering what is the more popular?

Always check the definitive source, namely the Sun site. In the article at
<http://java.sun.com/j2ee/1.4/docs/tutorial/doc/BMP2.html> you'll find the
following statements:
"If a finder method returns a single primary key and the requested entity
does not exist, the method should throw the javax.ejb.ObjectNotFoundException
(a subclass of FinderException). If a finder method returns a collection of
primary keys and it does not find any objects, it should return an empty
collection."
b). Declarative transactions for session bean methods
Should I by default make all session bean retrieval related methods have a
'not supported' transaction setting?

You could, but wouldn't it make more sense to examine the root cause of a
failure? Ignoring the fact that a customer couldn't be found and creating
a purchase order anyway just doesn't sound right to me... ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top