• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

BMP

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
ALaxmi Shankaran
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My EJB method is as like --

public Collection ejbFindCompanyRecords(){
Collection companyCollection=new ArrayList();


try {
-- got connection
-- created statement
-- resultset
-- populated collection
-- closed resources used

} catch(SQLException sqlExc){

} catch(NamingException namingExc){

}finally{
try{
-- closed resources if any open
}catch(SQLException sqlExc){

}
}
return companyCollection;
}

My Home interface is as like --

public Collection findCompanyRecords()
throws FinderException,RemoteException;


My deployment descriptor as like --

<entity>
<display-name>Company</display-name>
<ejb-name>Company</ejb-name>
<home>company.CompanyHome</home>
<remote>company.Company</remote>
<ejb-class>company.CompanyEJB</ejb-class>
<persistence-type>Bean</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
<reentrant>False</reentrant>
<resource-ref>
-- proper resource reference here
</resource-ref>
</entity>



My servlet part of code --

InitialContext context = new InitialContext();
Object ref=context.lookup("Company");
CompanyHome companyHome=(CompanyHome)PortableRemoteObject.narrow(ref,CompanyHome.class);
Collection companyCollection=companyHome.findCompanyRecords(); // Here it gives exception ..........

I am getting exception as ....

java.lang.ClassCastException: java.lang.String
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


-- got connection
-- created statement
-- resultset
-- populated collection
-- closed resources used


And I suppose you populate your collection with a list of primary keys (Integer objects I suppose).
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
'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
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it will return a collection of remote interfaces.
Regards.
 
Balamaci Serban
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

By using a session facade pattern.

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();
.
.
.
}


On the server side in the SessionBean

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 ]
 
Get out of my mind! Look! A tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic