Hi all First time i am using BMP EJB In one BMP i have written one Finder method as ejbFindCompanyRecords which returns a Collection Also i have declared that in the home interface. public Collection ejbFindCompanyRecords() throws FinderException,RemoteException; From servlet ,I am calling this finder method as Collection companyCollection=companyHome.findCompanyRecords();
it compiles well but while run time it gives me casting exception I am confused wether to create the remote instance or not...
You might need to share your code with us and provide the error stack trace. However I expect that you get a reference to the home interface in this way:
Using the local home interface. Another alternative is to narrow rather than casting:
Using the remote interface. My guess is that for whatever reasons your syntax for casting/narrowing is maybe wrong. But as I said you must share your code with us. Let me know if you need any more help. Regards.
I think, therefore I exist -- Rene Descartes
ALaxmi Shankaran
Greenhorn
Joined: Feb 23, 2004
Posts: 26
posted
0
My EJB method is as like --
public Collection ejbFindCompanyRecords(){ Collection companyCollection=new ArrayList();
try { -- got connection -- created statement -- resultset -- populated collection -- closed resources used
'fraid I'm here with some questions and not answers Ok, i know that in the Bean class in the Collection findCompanyRecords() method, the returned collection is one of Integers. Ok, but in the CompanyHome we have Collenction findCompanyRecords() which return what? It returns a colection of say CompanyRemote extends EJBObjects objects?
Is this correct? [ March 21, 2005: Message edited by: Balamaci Serban ]
Valentin Tanase
Ranch Hand
Joined: Feb 17, 2005
Posts: 704
posted
0
Yes it will return a collection of remote interfaces. Regards.
Balamaci Serban
Ranch Hand
Joined: Mar 16, 2005
Posts: 49
posted
0
Cheers guys, Ok, my next question will somehow deviate from the initial question but it still in the domain of returned Collection and findAll getter.
On the client 1.lookup Session home; 2.create remote interface named say remote_conection 3.get all the records to be just displayed. remote_conection.getAllRecords()
Is the wright way to go on this?
We would both have on the server and on the client the class Record: public class Record implements Serializable { private int id; private String name; private double value;
public Record(int id_t,String name_t,double value_t); public int getId(); . . . }
public Collection getAllRecords() { Vector v=new Vector(); //get home of the records entity bean; Iterator it=home.findCompanyRecords().iterator();
while(it.hasNext()) {
//getting from the Company Entity bean the records remote=(CompanyRemote) javax.rmi.PortableRemoteObject.narrow(i.next(),CompanyRemote.class);
//fillup the Record class Record rcd=new Record(remote.getId(),remote.getName(),remote.getValue()); v.add(rcd); } return v; }
And on the client side we need to suply the Record class and begin the whole thing again
Iterator it=remote_conection.getAllRecords().iterator(); while(it.hasNext()) { Record r=(Record)i.next(); }
Now is it just me or some other people feel entangled and get to confuse some things with other? I know the session facade is not there to just mimic all the entity beans methods, but besides the bussines stuff employed in the session bean, there will be times when you would need to return some collections to the client, the records in the database. So the question: is that how you would do it? Another Serializable class that you need time to fill up with the records returned by the entity bean and gets passed to the client(it seems to me like doing something twice)? [ March 22, 2005: Message edited by: Balamaci Serban ]