hey all,
my client calls on a session bean and session bean calls on an entity bean.
in entity bean, one of the methods is
[code]
public Collection ejbFindByxxx ( xx xx) {
Vector v = new Vector();
xxx
xxx
//
return v;
}
[/code]
my session bean calls on this method.. and what ever the result, passes on to the client.
[code]
public Collection callEntityBean(xx xx) {
Vector v = new Vector();
//look up entity bean..
v = home.findByxxx(xx xx);
return v;
}
[/code]
first thing, i am not sure i am doing it right.
second, when i compile my session bean, compiler complains Collection and Vector are incompatible. but this doesn't happen for entity bean. why? and how do i work around this?
thank you
lucy..
-
Collection/vector in EJB? (5 messages)
- Posted by: Dan Simles
- Posted on: March 30 2004 11:37 EST
Threaded Messages (5)
- Collection/vector in EJB? by David Rabinowitz on March 30 2004 12:58 EST
- Collection/vector in EJB? by Lauro Canonica on March 30 2004 13:36 EST
- Collection/vector in EJB? by Dan Simles on March 30 2004 14:15 EST
- Collection/vector in EJB? by Vijaykumar Natarajan on March 30 2004 15:01 EST
- Collection/vector in EJB? by Dan Simles on March 30 2004 16:35 EST
-
Collection/vector in EJB?[ Go to top ]
- Posted by: David Rabinowitz
- Posted on: March 30 2004 12:58 EST
- in response to Dan Simles
You are trying to force Collection into Vector.
Do the following:
[code]
public Collection callEntityBean(xx xx) {
//look up entity bean..
Collection c = home.findByxxx(xx xx);
return c;
}
[/code] -
Collection/vector in EJB?[ Go to top ]
- Posted by: Lauro Canonica
- Posted on: March 30 2004 13:36 EST
- in response to Dan Simles
or cast the collection you receive to a vector
[code]
public Vector callEntityBean(xx xx) {
//look up entity bean..
Vector v = (Vector) home.findByxxx(xx xx);
return v;
}
[/code]
Anyway consider repackaging your results into an ObjectValue before returning
it to an external application.
Lauro
http://www.nelcom.ch (J2EE in Ticino, Switzerland) -
Collection/vector in EJB?[ Go to top ]
- Posted by: Dan Simles
- Posted on: March 30 2004 14:15 EST
- in response to Dan Simles
hey all..
thanx all. i got the point. Still,
how come the same thing, converting a vector into collection object compiles in an entity bean but doesn't in session bean?
lucy.. -
Collection/vector in EJB?[ Go to top ]
- Posted by: Vijaykumar Natarajan
- Posted on: March 30 2004 15:01 EST
- in response to Dan Simles
That's because in the entity you are converting a vector to a collection whereas in your session you are converting a collection to a vector.
All vectors are collections, but not all collections are vectors. In your case, it happens to be so, but the VM doesn't know that. All it knows is that findByxxx returns a collection.
The error is in this line:
v = home.findByxxx(xx xx);
While you can cast to a vector, it is not good programming as you are relying on implementation details of findByxxx (which could return some other collection later). You should treat the return of findByxxx as a collection only (and not as a vector). -
Collection/vector in EJB?[ Go to top ]
- Posted by: Dan Simles
- Posted on: March 30 2004 16:35 EST
- in response to Dan Simles
hi,
that cleared it up.
thank you
lucy..