I'd suggest a slightly different approach. You say your ejbSelect returns
all instances, and then you are extracting the first one returned. However,
the container still needs to read the entire result set from the database
(unless you are pulling some trick with limit).

An alternative would be so have a simple finder with a query that returned
the single instance with the max id. You could write this in SQL as
SELECT MAX(ID) FROM TABLE
but the problem is that CMP uses a query format that allows columns to be
added for on-find read-ahead. This means you need a query more like
SELECT * FROM TABLE WHERE ID = (SELECT MAX(ID) FROM TABLE)
which is not supported by EJB-QL. However, you could do this with a
<declared-sql> query a bit like

  <query>
     <query-method>
       <method-name>findWithMaxId</method-name>
       <method-params/>
     </query-method>
     <declared-sql>
       <where>ID = (SELECT MAX(ID) FROM TABLE)</where>
     </declared-sql>
  </query>

This then becomes a simple finder:
  MyBean findWithMaxId()
which is easier from the coding viewpoint, and which performs better as you
only ever load a single record from the database.

Regards
Jeremy

/*************************
 * Jeremy Boynes
 * Partner
 * Core Developers Network
 *************************/


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of
[EMAIL PROTECTED]
Sent: Tuesday, June 10, 2003 7:52 AM
To: [EMAIL PROTECTED]
Subject: [JBoss-user] CMP and remote interfaces. USing ejbSelects within
remote finders.


Hi folks,
           I've just encountered a small problem concerning the
implementation of a method that returns the entity instance with the
greatest id.

ejbHomeRetrieveByMaxId().

Basically my entity bean only has a remote interface at the minute which is
proving to be the problem. I was using an ejbSelect method to
retrieve all the instances of the entity bean, ascendingly ordered by the
primary key (a long primitive).
If I'm correct and please set me straight if I'm not, the ejbSelect method
doesn't actually return a set of localHome objects but instead returns a set
containing all the primaryKeys for all the entities.

By this logic then if I retrieve the long value of the first element in the
set then I'll have the max id. By returning this value in the remote call
shouldn't
the container interrupt the call take the primary key value and then return
the remote EJBObject corresponding to this primary key?

I'm not sure how feasible it sounds but what I'm wondering is whether or not
there's a restriction on implementations of remote finder methods using
ejbSelect methods?

Is it incorrect practice for an entity bean to have both a remote and local
set of interfaces?
Is the container able to distinguish when to return the appropriate
interface?

Am I going about this the wrong way altogether?

Thanks,
Mark.



-------------------------------------------------------
This SF.net email is sponsored by:  Etnus, makers of TotalView, The best
thread debugger on the planet. Designed with thread debugging features
you've never dreamed of, try TotalView 6 free at www.etnus.com.
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to