Hi Pedro,
         Take a look at Jeremy's answer to my problem..

Ta,
Mark.

///////////////////

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] On Behalf Of
[EMAIL PROTECTED]
Sent: 10 June 2003 12:29
To: [EMAIL PROTECTED]
Subject: [JBoss-user] MAX function in jboss-ql




hi, i use jboss 3.2.1 with CMP2.0

do you know if MAX function in jboss-ql is avaliable?

if yes, where i use it? in SELECT or WHERE clausule?

if no, what can i do for know the field's maximun value?

thanks in advance.



-- 

     Pedro Barreiros     |     Simauria Networks
 ----------------------------------------------------
 [EMAIL PROTECTED] |   [EMAIL PROTECTED]
     Tlf: 620 199 405    |  http://www.simauria.net
 ----------------------------------------------------
         C/ Cádiz, 90 pta 6. 46006 Valencia.
    Tlf: +34 963.44.48.48 - Fax: +34 963.44.48.49
 ----------------------------------------------------



-------------------------------------------------------
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



-------------------------------------------------------
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