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 Grim Shieldsson <gr...@yahoo.com> on 2003/05/08 21:41:11 UTC

Complex Query problem

I have two objects:
class B {
  String name;
}
class A {
   B b;
}
I want to find all A's with B's name like "foo*".
Afaik, the oql should look like this:

select obj 
from obj in A 
where obj.b.name like "foo*"

I have also tried
select obj
from A
where b.name like "foo*"
which results in NPE

However I'm getting a NPE with a message of unexpected token "in".
How should this look?


=====
Grim Shieldsson (James A Barrows)
Acting Chieftain of Clan StormWolf
Barbarian Freehold Alliance
 "The real destroyer of the liberties of the people is he who spreads among them bounties, donations and benefits." 
--Plutarch

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

Re: Complex Query problem

Posted by Grim Shieldsson <gr...@yahoo.com>.
--- Peter Gaus <pe...@gaus-net.de> wrote:
<SNIP>
> 
>    // set the OQL select statement
>    query.create( "select obj " +
>                  "from " + A.class.getName() + " " +
>                  "where obj.names.name = $1" );

I've tried this, and get a class cast exception.
Must be the difference between 1-1 and 1-n.

James Barrows
Software Developer
Modern Medieval Sports



__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

Re: Complex Query problem

Posted by Peter Gaus <pe...@gaus-net.de>.
Hi Grim,

I had a similiar problem, but with an 1:n connection between the to
classes:
class B {
   String name;
}
class A {
   Vector names = new Vector();  // contains objects of class B
}

Here is my solution, perhaps it will help you:
   Transaction ta = odmg.newTransaction();
   ta.begin();
      
   // get an OQLQuery object from the ODMG facade
   OQLQuery query = odmg.newOQLQuery();

   // set the OQL select statement
   query.create( "select obj " +
                 "from " + A.class.getName() + " " +
                 "where obj.names.name = $1" );

   // bind the $1 in the query
   B b = new B( "foobar" );
   query.bind( b.getName() );

   // perform the query and store the result
   // in a persistent Collection
   DList curls = (DList) query.execute();

   ta.commit();

That's it. I'm using RC2

Peter


-----Ursprüngliche Nachricht-----
Von: Grim Shieldsson [mailto:grimshieldsson@yahoo.com] 
Gesendet: Donnerstag, 8. Mai 2003 22:02
An: OJB Users List
Betreff: Re: Complex Query problem


I forgot, using RC1
--- Grim Shieldsson <gr...@yahoo.com> wrote:
> I have two objects:
> class B {
>   String name;
> }
> class A {
>    B b;
> }
> I want to find all A's with B's name like "foo*".
> Afaik, the oql should look like this:
> 
> select obj 
> from obj in A 
> where obj.b.name like "foo*"
> 
> I have also tried
> select obj
> from A
> where b.name like "foo*"
> which results in NPE
> 
> However I'm getting a NPE with a message of unexpected token "in".
> How should this look?
> 
> 
> =====
> Grim Shieldsson (James A Barrows)
> Acting Chieftain of Clan StormWolf
> Barbarian Freehold Alliance
>  "The real destroyer of the liberties of the people is he who spreads
> among them bounties, donations and benefits." 
> --Plutarch
> 
> __________________________________
> Do you Yahoo!?
> The New Yahoo! Search - Faster. Easier. Bingo.
> http://search.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 


=====
Grim Shieldsson (James A Barrows)
Acting Chieftain of Clan StormWolf
Barbarian Freehold Alliance
 "The real destroyer of the liberties of the people is he who spreads
among them bounties, donations and benefits." 
--Plutarch

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

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


Re: Complex Query problem

Posted by Grim Shieldsson <gr...@yahoo.com>.
I forgot, using RC1
--- Grim Shieldsson <gr...@yahoo.com> wrote:
> I have two objects:
> class B {
>   String name;
> }
> class A {
>    B b;
> }
> I want to find all A's with B's name like "foo*".
> Afaik, the oql should look like this:
> 
> select obj 
> from obj in A 
> where obj.b.name like "foo*"
> 
> I have also tried
> select obj
> from A
> where b.name like "foo*"
> which results in NPE
> 
> However I'm getting a NPE with a message of unexpected token "in".
> How should this look?
> 
> 
> =====
> Grim Shieldsson (James A Barrows)
> Acting Chieftain of Clan StormWolf
> Barbarian Freehold Alliance
>  "The real destroyer of the liberties of the people is he who spreads
> among them bounties, donations and benefits." 
> --Plutarch
> 
> __________________________________
> Do you Yahoo!?
> The New Yahoo! Search - Faster. Easier. Bingo.
> http://search.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 


=====
Grim Shieldsson (James A Barrows)
Acting Chieftain of Clan StormWolf
Barbarian Freehold Alliance
 "The real destroyer of the liberties of the people is he who spreads among them bounties, donations and benefits." 
--Plutarch

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com