Hi,
one time you use ejbFind* and other time find*
ejbFind* methods are collections of primary keys
find* methods are collections of EJBObjects.
--- John Dubchak <[EMAIL PROTECTED]> schrieb: > Hi,
>
> I am using JBoss 2.1 beta with Embedded Tomcat
> support and have
> encountered what appears to be a bug in jBoss.
>
> I have created a BMP EJB with the following custom
> finder:
>
> public Collection ejbFindByLastname(String n)
> throws FinderException
> {
> LinkedList l = null;
> Connection conn = null;
>
> try
> {
> Context ctx = new InitialContext(properties);
> DataSource ds =
> (DataSource)ctx.lookup("java:/ContactsDB");
>
> String query = "SELECT name_key FROM name
> WHERE lastname = '" + n
> + "'";
> conn = ds.getConnection();
> Statement stmt = conn.createStatement();
> ResultSet rs = stmt.executeQuery(query);
>
> l = new LinkedList();
> while(rs.next())
> {
> l.add(new Integer(rs.getInt(1)));
> }
>
> rs.close();
> stmt.close();
> }
> catch(Exception e)
> {
> }
> finally
> {
> if(conn != null)
> try {conn.close();} catch(SQLException e) {}
> }
>
> return l;
> }
>
> This code, using a simple test schema, creates a
> linked list with two
> Integer values (1 and 5), which represent the
> primary keys of two
> different rows in the database that match a
> particular search of
> lastname. This works fine. The problem comes when
> I use the following
> client code to access these Integer based keys and
> try to do a further
> lookup on them:
>
> try
> {
> // Get a reference to the Interest Bean
> Object ref = ctx.lookup("ContactName");
>
> // Get a reference from this to the Bean's
> Home interface
> ContactNameHome home = (ContactNameHome)
> PortableRemoteObject.narrow (ref,
> ContactNameHome.class);
>
> Collection c = home.findByLastname(lname);
>
> Iterator iter = c.iterator();
> while(iter.hasNext())
> {
> Integer i = (Integer)iter.next();
> this.display(i); // Custom method to
> lookup PK and display row
>
> }
> }
>
> The above code, in the while loop throws a class
> cast exception. Rather
> than the collection being a linked list of Integer
> objects from above,
> it a collection of Proxy objects (Remote stubs). So
> if I change that
> code to:
>
> // Name of my Remote Interface
> ContactName cnt = (ContactName)iter.next();
> this.display(cnt.getBusinessObject());
>
> it will only work as long as the objects
> (ContactName) are in cache. If
> I haven't previously looked up these objects, I will
> get a NULL
> reference. On the other hand, if I have looked them
> up, my linked list,
> which is supposed to be Integer objects is actually
> a list of Remote
> Interface references that have been obtained from
> the cached objects on
> the server side.
>
> Has anyone else experienced this problem?
>
> Thanks,
> John
>
>
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
>
http://lists.sourceforge.net/lists/listinfo/jboss-user
__________________________________________________________________
Do You Yahoo!?
Gesendet von Yahoo! Mail - http://mail.yahoo.de
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user