J2EE + Beans advice required

J

James Willans

I need to implement a simple J2EE application (in actual fact, I think
it is just a beans application). Unfortunately I have limited
understanding of the technologies surrounding J2EE and java beans. I
have read through bits of tutorials which have helped my
understanding, unfortunately there are still some loose ends which I
hope someone can help tie up.

The application I wish to implement involves the user being able to
create multiple instances of a bean (say "contact"), which they can
then display and edit (very simple!). I am using a session bean as a
facade so that the containership of the instances of "contact", which
is implemented as an entity bean, can be automatically managed.

Firstly here is the home interface for "contact":

public interface Contact extends EJBHome {

public Contact create(String id, String name,String phone)
throws CreateException, RemoteException;

public Contact findByPrimaryKey(String id)
throws FinderException, RemoteException;

public Collection findAll()
throws RemoteException, FinderException;
}

Question 1: I'm assuming that I don't need a remote interface for this
since it is always accessed via the facade (but see Question 2,
below). Is this correct?

Here is the entity bean logic:

public class Contact implements EntityBean {

private String id;
private String name;
private String phone;

public String getId() {
return id;
}

// getter and setter for "name" and "phone" removed

public void ejbCreate(String id,String name,String phone)
throws CreateException, RemoteException {

this.id = id;
this.name = name;
this.phone = phone;
}

public void setEntityContext(javax.ejb.EntityContext ctx)
throws RemoteException {}
public void unsetEntityContext() throws RemoteException {}
public void ejbRemove() throws RemoteException, RemoveException {
}
public void ejbActivate() throws RemoteException { }
public void ejbPassivate() throws RemoteException { }
public void ejbLoad() throws RemoteException { }
public void ejbStore() throws RemoteException { }
}

It is from the session facade that most of my questions stem:

Question 2: What types of values can a bean's remote interface return?
Could it return a Collection of Contact bean instances? If so, do I
need to do anything special (like making the Contact bean
serializable).

Question 3: I'm assuming that if 2 was possible, then a copy of the
instance would be returned, therefore changing its state would not
impact the original?

Many thanks.

James
 
P

Phillip Mills

Question 1: I'm assuming that I don't need a remote interface for this
since it is always accessed via the facade (but see Question 2,
below). Is this correct?

Yes. If they always share a JVM with their callers, local should be
enough.
Question 2: What types of values can a bean's remote interface return?
Could it return a Collection of Contact bean instances? If so, do I
need to do anything special (like making the Contact bean
serializable).

If I understand correctly, I think you're looking for "find" methods and
EJB QL.
Question 3: I'm assuming that if 2 was possible, then a copy of the
instance would be returned, therefore changing its state would not
impact the original?

If you have an entity bean, state changes are persistent. To get copies
of the data from an entity bean (or a related set of them), a common
method is to create data transfer objects as intermediates.
<http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.
html>

(Note: These URL's are just samples from Google searches...not
necessarily the best and brightest.)
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top