A small problem with BMP. I need some methods to return large amounts
of data. I noticed that initializing a new entity bean for every single
data item (there are more than 50,000 rows), is very time consuming and
not really required in this scenario. So I switched to BMP and defined
the following finder method:
public Collection ejbFindByCompanyId (long companyId)
throws FinderException, RemoteException
{
Connection connection = null;
PreparedStatement prepStmt = null;
ResultSet result = null;
ArrayList list = new ArrayList();
try {
connection = this.dataSource.getConnection();
prepStmt = connection.prepareStatement (companyIdQuery);
prepStmt.setLong (1, companyId);
result = prepStmt.executeQuery();
while (result.next()){
loadStakeholderData (result);
if (this.id > 0) {
StakeholderData data = new StakeholderData();
data.id = this.id;
data.companyId = this.companyId;
data.firstName = this.firstName;
data.lastName = this.lastName;
data.email = this.email;
data.createdBy = this.createdBy;
data.dateCreated = this.dateCreated;
data.mimeTypePreference = this.mimeTypePreference;
data.modifiedBy = this.modifiedBy;
data.neverContact = this.neverContact;
data.optInType = this.optInType;
data.optInVerification = this.optInVerification;
data.source = this.source;
data.validEmail = this.validEmail;
data.lastModified = this.lastModified;
list.add (data);
System.out.println ("ejbFindByCompanyId: Adding " +
data.email);
}
else {
System.out.println ("Invalid Stakehodler.id" +
this.id);
}
}
return list;
}
catch (SQLException e){
throw new EJBException (e.getMessage());
}
finally {
JDBCHelper.close (connection, prepStmt, result);
}
}
Note that StakeholderData is a class implementing Serializable. Now,
when I call this finder from a session bean like:
public ArrayList getCompanyStakeholders (StakeholderData data)
throws RemoteException, FinderException, EntityDataException
{
this.verifyLongId ("StakeholderData", data.companyId);
try {
Collection c = this.stakeholderHome.findByCompanyId
(data.companyId);
ArrayList list = new ArrayList (c);
int size = list.size();
System.out.println ("list size = " + size);
for (int i = 0; i < size; i++ ){
StakeholderData o = (StakeholderData)list.get(i);
System.out.println (o.email);
}
return list;
}
catch (FinderException e){
throw new EJBException (e.getMessage());
}
}
I get the following:
[ClientController] list size = 20
[ClientController] TRANSACTION ROLLBACK EXCEPTION:null; nested exception
is:
javax.ejb.EJBException
[ClientController] java.lang.ClassCastException: $Proxy339
[ClientController] at
com.frontwire.cams.session.clientcontroller.ClientControllerEJB.getCompanyStakeholders(ClientControllerEJB.java)
[ClientController] at java.lang.reflect.Method.invoke(Native Method)
[ClientController] at
org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:472)
[ClientController] at
org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:87)
[ClientController] at
org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:133)
[ClientController] at
org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:263)
[ClientController] at
org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:99)
[ClientController] at
org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:190)
[ClientController] at
org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:195)
... 8<
Hmmm, I've tried this with the finder returning an ArrayList but had no
luck either
What did I do wrong or didn't do?
--
Nicolai P Guba http://www.gnu.org http://www.frontwire.com
mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED]
GSM: +44 (0)7909 960 751 DDI: +44 (0)20 7368 9708
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user