You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Marc Tinnemeyer <ma...@gmx.net> on 2004/08/17 00:59:40 UTC

object in QueryByCriteria

Dear Listmembers,

I got the following problem:

I try to retrieve an object via ojb using the PB API. The syntax looks
like this:

broker = PersistenceBrokerFactory.defaultPersistenceBroker();
QueryByCriteria query = new QueryByCriteria(oUser);            
result = (User) broker.getObjectByQuery(query);

the oUser object has several attributes, like id, name, username,
password ...

Now somebody tries to login and the attributes "username" and password"
are set. That object ist then passed as criteria to QueryByCriteria.

The weird thing is that the generated sql-statement looks like this:

SELECT
A0.username,A0.password,A0.id
WHERE (((A0.id = 0) AND A0.username = 'userabc') 
AND A0.password = 'myPassword')

My problem is A0.id = 0 !
And my question is, is there a way to tell ojb only to query the
attributes that are set ? 
s.th. like:

select
A0.username,A0.password,A0.id
where (( A0.username = 'abcUser') and A0.password = 'myPassword')

Currently my version of ojb is 1.0rc6.


Thanks in advance,

Kind regards,
Marc Tinnemeyer

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: object in QueryByCriteria

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi all,

when using primitives ojb canot distinguish int 0 from an uninitialized int
(0 as well), so it's better not to use primitives at all.

hth
jakob

> My guess is your attributes have primitive types. That
> is, oUser.id has type int rather than Integer. If you
> use the later then just do not set the attribute that
> you do not want to use in criteria and since it will then be null,
> it won't be looked at.
> 
> Ashish
> 
> 
> 
> Marc Tinnemeyer wrote:
>  > Dear Listmembers,
>  >
>  > I got the following problem:
>  >
>  > I try to retrieve an object via ojb using the PB API. The syntax looks
>  > like this:
>  >
>  > broker = PersistenceBrokerFactory.defaultPersistenceBroker();
>  > QueryByCriteria query = new QueryByCriteria(oUser);
>  > result = (User) broker.getObjectByQuery(query);
>  >
>  > the oUser object has several attributes, like id, name, username,
>  > password ...
>  >
>  > Now somebody tries to login and the attributes "username" and password"
>  > are set. That object ist then passed as criteria to QueryByCriteria.
>  >
>  > The weird thing is that the generated sql-statement looks like this:
>  >
>  > SELECT
>  > A0.username,A0.password,A0.id
>  > WHERE (((A0.id = 0) AND A0.username = 'userabc')
>  > AND A0.password = 'myPassword')
>  >
>  > My problem is A0.id = 0 !
>  > And my question is, is there a way to tell ojb only to query the
>  > attributes that are set ?
>  > s.th. like:
>  >
>  > select
>  > A0.username,A0.password,A0.id
>  > where (( A0.username = 'abcUser') and A0.password = 'myPassword')
>  >
>  > Currently my version of ojb is 1.0rc6.
>  >
>  >
>  > Thanks in advance,
>  >
>  > Kind regards,
>  > Marc Tinnemeyer
>  >
>  > ---------------------------------------------------------------------
>  > To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>  > For additional commands, e-mail: ojb-user-help@db.apache.org
>  >
>  >
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 

-- 
NEU: WLAN-Router f�r 0,- EUR* - auch f�r DSL-Wechsler!
GMX DSL = superg�nstig & kabellos http://www.gmx.net/de/go/dsl


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: object in QueryByCriteria

Posted by Marc Tinnemeyer <ma...@gmx.net>.
thanks a lot for your hint,

now the statements are generated as expected :-)

Marc


On Mon, 16 Aug 2004 17:11:22 -0600
Ashish Rangole <as...@vexcel.com> wrote:

> My guess is your attributes have primitive types. That
> is, oUser.id has type int rather than Integer. If you
> use the later then just do not set the attribute that
> you do not want to use in criteria and since it will then be null,
> it won't be looked at.
> 
> Ashish
> 
> 
> 
> Marc Tinnemeyer wrote:
>  > Dear Listmembers,
>  >
>  > I got the following problem:
>  >
>  > I try to retrieve an object via ojb using the PB API. The syntax
>  > looks like this:
>  >
>  > broker = PersistenceBrokerFactory.defaultPersistenceBroker();
>  > QueryByCriteria query = new QueryByCriteria(oUser);
>  > result = (User) broker.getObjectByQuery(query);
>  >
>  > the oUser object has several attributes, like id, name, username,
>  > password ...
>  >
>  > Now somebody tries to login and the attributes "username" and
>  > password" are set. That object ist then passed as criteria to
>  > QueryByCriteria.
>  >
>  > The weird thing is that the generated sql-statement looks like
>  > this:
>  >
>  > SELECT
>  > A0.username,A0.password,A0.id
>  > WHERE (((A0.id = 0) AND A0.username = 'userabc')
>  > AND A0.password = 'myPassword')
>  >
>  > My problem is A0.id = 0 !
>  > And my question is, is there a way to tell ojb only to query the
>  > attributes that are set ?
>  > s.th. like:
>  >
>  > select
>  > A0.username,A0.password,A0.id
>  > where (( A0.username = 'abcUser') and A0.password = 'myPassword')
>  >
>  > Currently my version of ojb is 1.0rc6.
>  >
>  >
>  > Thanks in advance,
>  >
>  > Kind regards,
>  > Marc Tinnemeyer
>  >
>  > ------------------------------------------------------------------
>  > --- To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>  > For additional commands, e-mail: ojb-user-help@db.apache.org
>  >
>  >
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: object in QueryByCriteria

Posted by Ashish Rangole <as...@vexcel.com>.
My guess is your attributes have primitive types. That
is, oUser.id has type int rather than Integer. If you
use the later then just do not set the attribute that
you do not want to use in criteria and since it will then be null,
it won't be looked at.

Ashish



Marc Tinnemeyer wrote:
 > Dear Listmembers,
 >
 > I got the following problem:
 >
 > I try to retrieve an object via ojb using the PB API. The syntax looks
 > like this:
 >
 > broker = PersistenceBrokerFactory.defaultPersistenceBroker();
 > QueryByCriteria query = new QueryByCriteria(oUser);
 > result = (User) broker.getObjectByQuery(query);
 >
 > the oUser object has several attributes, like id, name, username,
 > password ...
 >
 > Now somebody tries to login and the attributes "username" and password"
 > are set. That object ist then passed as criteria to QueryByCriteria.
 >
 > The weird thing is that the generated sql-statement looks like this:
 >
 > SELECT
 > A0.username,A0.password,A0.id
 > WHERE (((A0.id = 0) AND A0.username = 'userabc')
 > AND A0.password = 'myPassword')
 >
 > My problem is A0.id = 0 !
 > And my question is, is there a way to tell ojb only to query the
 > attributes that are set ?
 > s.th. like:
 >
 > select
 > A0.username,A0.password,A0.id
 > where (( A0.username = 'abcUser') and A0.password = 'myPassword')
 >
 > Currently my version of ojb is 1.0rc6.
 >
 >
 > Thanks in advance,
 >
 > Kind regards,
 > Marc Tinnemeyer
 >
 > ---------------------------------------------------------------------
 > To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
 > For additional commands, e-mail: ojb-user-help@db.apache.org
 >
 >




---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org