users@glassfish.java.net

General question about detachable EJB 3.1 entities

From: <glassfish_at_javadesktop.org>
Date: Thu, 21 Jan 2010 11:09:38 PST

Hi,

I've got a general question about detaching an entity and sending it towards to the client by using some session bean.

Let's imagine the following example... I've got an entity, let's say called BankAccountEntity, which consists of getters and setters for its attributes. Further it has got a [i]isValid()[/i] method to validate the account number for correctness. In the [i]isValid()[/i] method e.g. an 3rd party library will be used doing the necessary calculation.

When talking about detaching an entity, I will be thinking of something like this:

Client Code:
BankAccountFactoryRemote bacf = (BankAccountFactoryRemote) initialCtx.lookup(...);
BankAccount b = bacf.newBankAccount();

Code in the Session Bean:
public BankAccount newBankAccount() {
    return new BankAccountEntity();
}

Of course, BankAccountEntity is implementing the BankAccount interface, which is used at the client.

If the entity now gets detached (transferred to the client by using serialization) and the client works with the object by only knowing the interface, what actually happens to the isValid() method call... will it be executed locally at the client (as all the bytecode required will also be transferred to the client at time of detachment) or will calling isValid() at the client result in an RPC call and the isValid() method is executed at the application server?

What is the recommended approach for such situations, should such a [i]isValid()[/i] method gets outsourced to the session bean or is it common to have it in the entity class?

I'm looking forward to some enlightment... :-)
[Message sent by forum member 'anusplus' (anus.plus_at_gmx.de)]

http://forums.java.net/jive/thread.jspa?messageID=382219