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 kristen <kr...@yahoo.fr> on 2004/07/26 16:22:01 UTC
problem with a request with m:n relations (ojb)
Hello !
First, sorry for my english...
I would like to create a request which are based on a m:n relationships.
For example :
a book can be written by several authors and several authors can write books.
This is the relation :
book <-> writtenBy <-> author
For example, How can I obtain the name of all the author who have written the
book "my book" ?
I have the following code but I don't know how can I put several classes after
the "from" :
Transaction tx = odmg.newTransaction();
tx.begin();
OQLQuery query = odmg.newOQLQuery();
String queryStr = "select auhors from " + Author.class.getName()+ .... ?
query.create(queryStr);
GroupsList = (List) query.execute();
tx.commit();
Thank you for your help
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: problem with a request with m:n relations (ojb)
Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi kristen,
ojb does the join automatically:
query.create("select authors ...Autor where books.title like ?");
this sample need a relationship-definition named 'books' and an attribute
'title' in class Books. the relationship 'books' is a bidirectional m:n
relationship based on the table writtenBy.
jakob
kristen schrieb:
> Hello !
>
> First, sorry for my english...
>
> I would like to create a request which are based on a m:n relationships.
>
> For example :
>
> a book can be written by several authors and several authors can write books.
>
>
> This is the relation :
>
> book <-> writtenBy <-> author
>
> For example, How can I obtain the name of all the author who have written the
> book "my book" ?
>
> I have the following code but I don't know how can I put several classes after
> the "from" :
>
> Transaction tx = odmg.newTransaction();
> tx.begin();
> OQLQuery query = odmg.newOQLQuery();
> String queryStr = "select auhors from " + Author.class.getName()+ .... ?
>
> query.create(queryStr);
> GroupsList = (List) query.execute();
> tx.commit();
>
>
> Thank you for your help
>
>
> ---------------------------------------------------------------------
> 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