I am testing remote access with a JSP in one server and session/entity bean in another server. Before adding a record into database, the program perform a find. If it is a new record, the find returns null and the add record was successful. But if a record is already exist, find fails with exception error message "java.lang.reflect.UndeclaredThrowableException". The same program if deployed in the SAME server did not give such problems. Listed below are part of my program. Could the problem cause by the object being passed remotely from one server to the other server where the client program resides????
[JSP]
AccountMaintenance account = null;
InitialContext ctx = new InitialContext();
account = (AccountMaintenance) ctx.lookup(AccountMaintenance.class.getName());
if ((request.getParameter ("name") != null) && (request.getParameter ("type") != null) &&
(request.getParameter ("balance") != null)) {
command = request.getParameter ("action");
name = request.getParameter ("name");
type = request.getParameter ("type");
balance = Double.parseDouble(request.getParameter ("balance"));
if (command.equals("Add")) {
try {
// The find returns exception error if a record already exists
Account myAccount = account.find(name);
if (myAccount != null) {
errormsg = "Account already exists";
} else {
account.add(name, type, balance);
}
} catch (Exception e) {
errormsg = e.toString();
}
}
[Session Bean]
@Stateless
@Remote(AccountMaintenance.class)
public class AccountMaintenanceBean implements AccountMaintenance {
@PersistenceContext(unitName="MySqlMgr")
private EntityManager manager;
public void add(String actName, String actType, double actBalance) {
try {
Account account = new Account();
account.setActActive(true);
account.add(actName, actType, actBalance);
manager.persist(account);
}
catch (Exception e) {
}
}
public Account find(String actName) {
return manager.find(Account.class, actName);
}