Re: customize finder method

2000-10-19 Thread Joe Walnes

Actually it makes more sense to place the % in the finder method as it
abstracts the SQL from the underlying code. A developer working with entity
beans should never need to use any SQL (even if it only is one character).

The reason the attempted finder method isn't working is to do with how JDBC
prepared statements work.

To fix the problem, in your finder-method tag in the deployment
descriptor, replace:

like '%$1%'

... with ...

like '%' + $1 + '%'

-Joe Walnes

- Original Message -
From: "DeVincentiis Giustino" [EMAIL PROTECTED]
To: "Orion-Interest" [EMAIL PROTECTED]
Sent: Thursday, October 19, 2000 11:59 AM
Subject: R: customize finder method


Hi Leung,
You should'nt use the '%' symbols in the finder definition, instead you
should attach them to the parameter you pass to the finder method.
i.e.
finder definition:
finder-method query="select catname,description from cat_ejb_Category
where $description like $1"
finder calling:
findBy...("%" + description + "%");

Hope this help
Giustino De Vincentiis


-Messaggio originale-
Da: Yeung Man Leung [mailto:[EMAIL PROTECTED]]
Inviato: giovedì 19 ottobre 2000 9.57
A: Orion-Interest
Oggetto: customize finder method


Hi all,
I have try to customize the a findBy method in one of my Bean in the
following.
finder-method query="select catname,description
from cat_ejb_Category where $description like '%$1%'" partial="false"
!-- Generated SQL: "select
catname,description from cat_ejb_Category where
cat_ejb_Category.description like '%?%'" --
method

ejb-namecat.ejb.Category/ejb-name

method-namefindByDesc/method-name
method-params

method-paramjava.lang.String/method-param
/method-params
/method
/finder-method

   However when I try to execute the findBy method,
I got the following exception:
com.evermind.server.rmi.OrionRemoteException: Database error:
ORA-01006: bind variable does not exist

Did anyone know what went wrong in my sql, thx

Leung







RE: customize finder method

2000-10-19 Thread Amir Peivandi

I agree Joe, but can you tell me how did you find out about this? I had the
same problem long time ago and I end up with Giustino's solution! Just want
to learn how to find the best answer to my questions.

:)

Amir


-Original Message-
From: Joe Walnes [mailto:[EMAIL PROTECTED]]
Sent: Thursday, October 19, 2000 7:17 AM
To: Orion-Interest
Subject: Re: customize finder method


Actually it makes more sense to place the % in the finder method as it
abstracts the SQL from the underlying code. A developer working with entity
beans should never need to use any SQL (even if it only is one character).

The reason the attempted finder method isn't working is to do with how JDBC
prepared statements work.

To fix the problem, in your finder-method tag in the deployment
descriptor, replace:

like '%$1%'

... with ...

like '%' + $1 + '%'

-Joe Walnes

- Original Message -
From: "DeVincentiis Giustino" [EMAIL PROTECTED]
To: "Orion-Interest" [EMAIL PROTECTED]
Sent: Thursday, October 19, 2000 11:59 AM
Subject: R: customize finder method


Hi Leung,
You should'nt use the '%' symbols in the finder definition, instead you
should attach them to the parameter you pass to the finder method.
i.e.
finder definition:
finder-method query="select catname,description from cat_ejb_Category
where $description like $1"
finder calling:
findBy...("%" + description + "%");

Hope this help
Giustino De Vincentiis


-Messaggio originale-
Da: Yeung Man Leung [mailto:[EMAIL PROTECTED]]
Inviato: giovedì 19 ottobre 2000 9.57
A: Orion-Interest
Oggetto: customize finder method


Hi all,
I have try to customize the a findBy method in one of my Bean in the
following.
finder-method query="select catname,description
from cat_ejb_Category where $description like '%$1%'" partial="false"
!-- Generated SQL: "select
catname,description from cat_ejb_Category where
cat_ejb_Category.description like '%?%'" --
method

ejb-namecat.ejb.Category/ejb-name

method-namefindByDesc/method-name
method-params

method-paramjava.lang.String/method-param
/method-params
/method
/finder-method

   However when I try to execute the findBy method,
I got the following exception:
com.evermind.server.rmi.OrionRemoteException: Database error:
ORA-01006: bind variable does not exist

Did anyone know what went wrong in my sql, thx

Leung







Re: customize finder method

2000-10-19 Thread Joe Walnes

I agree Joe, but can you tell me how did you find out about this? I had the
same problem long time ago and I end up with Giustino's solution! Just want
to learn how to find the best answer to my questions.

Figured it out :-)

If $1 is a String, it is escaped and quoted before putting it in the SQL
statement. So if $1 = "Joe's Test", it gets interpolated as 'Joe\'s Test'.
Therefore:

like '%$1%'  --  like '%'Joe\'s Test'%'   (invalid SQL)

like '%' + $1 + '%'  --  like '%' + 'Joe\'s Test' + '%'  (valid SQL)

-Joe Walnes