• Post Reply Bookmark Topic Watch Topic
  • New Topic

Please Help!!!!Trouble running Bean Managed Persistence Entitty Bean in WebSphere....  RSS feed

 
Gaurav Saxena
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all
I am new to J2EE as well as Websphere. I am trying to run this AccountBean Example given in the MasteringEJB pdf, in WAS release 4.0.1 Advanced Single Server Edition, OS is Windows 2000 server.The database used is IBM DB2 v7.2.
In the Bean class there is this method "ejbFindByOwnerName(String Name)" that returns an Enumeration object. When the client calls this method(from the command prompt using "launchclient" command), it throws an exception. The satck trace is as follows:-
Caught exception!
java.util.NoSuchElementException
at com.ibm.ejs.persistence.FinderEnumerator.nextElement(FinderEnumerator.java:122)
at com.ibm.ejs.persistence.FinderEnumeration.nextElement(FinderEnumeration.java:42)
at examples.account.AccountClient.main(AccountClient.java:81)
at java.lang.reflect.Method.invoke(Native Method)
at com.ibm.websphere.client.applicationclient.launchClient.createContainerAndLaunchApp(launchClient.java:430)
at com.ibm.websphere.client.applicationclient.launchClient.main(launchClient.java:288)
at java.lang.reflect.Method.invoke(Native Method)
at com.ibm.ws.bootstrap.WSLauncher.main(WSLauncher.java:158)
Destroying account..
in the command prompt where server is started the log is something like this:-
[00.06.07 11:11:21:033 GMT+05:30] 125e2d81 SystemOut U New Bank Account Entity Bean Java Object created by EJB Containe
r.
[00.06.07 11:11:21:043 GMT+05:30] 125e2d81 SystemOut U setEntityContext called
[00.06.07 11:11:21:043 GMT+05:30] 125e2d81 SystemOut U ejbFindByOwnerName(John Smith) called

the code for the Finder method is as follows:-
public Enumeration ejbFindByOwnerName(String name) throws FinderException, RemoteException {
PreparedStatement pstmt = null;
Connection conn = null;
Vector v = new Vector();
try {
System.out.println("ejbFindByOwnerName(" + name + ") called");

/*
* Acquire DB connection
*/
conn = getConnection();

/*
* Find the primary keys in the DB
*/
pstmt = conn.prepareStatement("select id from accounts where ownerName = ?");
pstmt.setString(1, name);
ResultSet rs = pstmt.executeQuery();
/*
* Insert every primary key found into a vector
*/
while (rs.next()) {
String id = rs.getString("id");
v.addElement(new AccountPK(id));
}

/*
* Return an enumeration of found primary keys
*/
return v.elements();
}
catch (Exception e) {
throw new FinderException(e.toString());
}
finally {
/*
* Release DB Connection for other beans
*/
try {
pstmt.close();
}
catch (Exception e) { }
try {
conn.close();
}
catch (Exception e) { }
}
}
and the code of the client is as given below:-
Enumeration e = home.findByOwnerName("John Smith");
if (e != null)
{
account = (Account) e.nextElement();
}
else {
throw new Exception("Could not find account");
}
please help!!!
Thanx in advance
Gaurav
 
Dave Coombes
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure your client code is correct. You test that the Enumeration is not null, but it could still be empty. you should use something like
while(e.hasMoreElements()) {
account = (Account)e.nextElement();
}
to iterate over the enumeration.
Cheers
Dave
 
Gaurav Saxena
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx for the reply dave but the problem is solved...
the problem was not with the code but with the container(Websphere 4.0.1 Application Server advanced single server edition). The problem was that it was using CORBA specs... so when returning the enumeration i have to use soemthing called "PortableRemoteObject.narrow" ... that solved the problem (sigh) FINALLY.
thanx any way
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!