I'm relatively new to developing on JavaEE. I'm wondering what the best format is in terms of passing parameters into a session bean for object creation or deletion calls.
For my backend, I use a DTO with a DAO to run create, update, delete and read operations on the database
public class BusinessObject {
public String name;
public int id;
// Assume constructor to init these 2 fields.
}
I have a simple DAO interface:
public interface BusinessDAO {
public void createBusinessObject(BusinessObject bo);
public void deleteBusinessObject(BusinessObject bo);
public void updateBusinessObject(BusinessObject bo);
public void findBusinessObject(BusinessObject bo);
}
(I believe the implementation of BusinessDAO
at this stage is irrelevant)
So on to my actual question - If I have a remote (stateless session bean) EJB interface, should I define a method inside the remote EJB interface:
public void addBusinessObject(String name, int id);
Or something along the lines of:
public void addBusinessObject(BusinessObject bo);
I have a simple client program that would call either of these methods.
My thoughts is that for object creation the BusinessObject bo
definition will work better, however I seem to think there is a pattern I can follow for other definitions in the remote interface.
I don't see how I can incorporate the same style of method definition for something like findObject(BusinessObject bo)
Is the standard practice to create the BusinessObject
and only provide say the ID field in that object, then the DAO implementation returns the filled in object back to the client (via the session bean)?
Or is it better to pass an int id
into the findObject
method instead and just return a BusinessObject
?