The findBy... method should return a reference to the remote interface of the entitybean (the ejbFindBy... the primarykey), on that remote interface you can call a method to get the Collection. interface MyEBHome extends javax.ejb.EJBHome { public MyEB findByCompanyId(long companyId) throws ....; } class MyEBBean implements javax.ejb.EntityBean { public long ejbFindByCompanyId(long companyId) throws .... { // check if primary key is in db and return it ... } } interface MyEB extends javax.ejb.EJBObject { public Collection getCompanyStakeholders(long companyId) throws ....; } Annegret > -----Original Message----- > From: Nicolai P Guba [SMTP:[EMAIL PROTECTED]] > Sent: Dienstag, 31. Juli 2001 12:23 > To: [EMAIL PROTECTED] > Subject: [JBoss-user] java.lang.ClassCastException: $Proxy339 > > 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.getCompany > Stakeholders(ClientControllerEJB.java) > [ClientController] at java.lang.reflect.Method.invoke(Native Method) > [ClientController] at > org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(Statel > essSessionContainer.java:472) > [ClientController] at > org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(Stateless > SessionInstanceInterceptor.java:87) > [ClientController] at > org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:13 > 3) > [ClientController] at > org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCM > T.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 _______________________________________________ JBoss-user mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-user
RE: [JBoss-user] java.lang.ClassCastException: $Proxy339
Sternagel Annegret (PN-SYS/DAS) Tue, 31 Jul 2001 06:40:28 -0700
- [JBoss-user] java.lang.ClassCastException:... Nicolai P Guba
- RE: [JBoss-user] java.lang.ClassCastE... Sternagel Annegret (PN-SYS/DAS)
- RE: [JBoss-user] java.lang.ClassC... Nicolai P Guba