When you use the finde method you have to think the same way as when youre
using 
a PreparedStatement. a value of ' name = = ' will be expanded to the
following when a string is set into the prepared statement: ' name =
'string' '

so query="name like '%value'" is not likely to work if its a parameter, BUT
if its a static value it works :)

There is a couple of matters you have to take into consern depending on what
database that is in the bottom of the system.

1) never set the dynamic value as the first in a comparance ie. "$1 = $name"
you should allways set the field name first ie. "$name = $1" because of the
database optimizer.

2) when using like keyword the best way to use it is to inform the users
that % is the wildchar and then you will soon see some extremely cool usage
of your finder methods :) ive seen search criterias like this before:
"Fa%li%ca%" :) to use this in your finder use: query="$name like $1".'

3) remember its the field mapping inside your bean that is used to search
against first in your appserver, so you should use the cmp field name not
the percistence name in your finder query.

So your fantasia example (<finder-method query="$1 LIKE '%' + $FANTASIA +
'%'">)
should be written: <finder-method query="$_fantasia LIKE '%' + $1 + '%'">

But still my preference is to inform the users and do <finder-method
query="$_fantasia LIKE $1"> :)

This is because if a user wants to type in a name without wildchars the
database woill optimize the like the same way as if you did = in the select
and the user will have better controll over the search... If you want the
programmer to have control, you should make a session proxy bean that will
add the % to the field, then the entity beans finder method can be used for
more than that one spesific usage. Where I work we allways put a session
proxy bean between the entity beans so we can chew the finder data before we
do the search, so the entity layers finder method can be made more reusable
throug the applications inside the appserver.

Hope this helps you :)

Klaus Myrseth
Telenor Mobil AS - PlanIT




-----Opprinnelig melding-----
Fra: Nick Newman [mailto:[EMAIL PROTECTED]]
Sendt: 19. september 2000 17:15
Til: Orion-Interest
Emne: Re: Doubts on finder methods & orion-ejb-ar.xml


Hi Sven,

The field names should be the "name", not the "persistence-name".  So you
should use "$1 = $_fantasia".  You can check this by viewing the generated
SQL after deployment.

I'm not sure about the LIKE construction - but it sounds reasonable.

Nick

At 10:23 AM 9/19/00 -0300, you wrote:
>I have a couple of doubts concerning the <finder-method > tag.
>specifically, I would like to implement a query like "select * from
>table where field LIKE '%value'"
>
>Considering I have:
>                       <cmp-field-mapping name="_fantasia"
persistence-name="FANTASIA" />
>in my orion-ejb-jar.xml.
>and the docs tell me:
> <finder-method partial="true|false" query="$1 = $myField AND
>$myOtherField > 5"> 
>I suppose (not really clear in the docs) that $1 is the value passed to
>the finder method and $MyField is the persistence name, in the above
>example FANTASIA and not _fantasia. Is that correct?
>
>in this case can I create a query like:
>                       <finder-method query="$1 LIKE '%' + $FANTASIA +
'%'">
>
>Sven
>-- 
>===========================================================================
=
>==========
>Sven E. van 't Veer                                          
>http://www.cachoeiro.net
>Java Developer
[EMAIL PROTECTED]
>===========================================================================
=
>==========


Reply via email to