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 nwbr <nw...@terra.com.br> on 2005/06/09 23:47:09 UTC

query issue (join)

 
Hi,
 
I have the model listed bellow(at end of mail), and I'm having some
problem to do a query. I wanna list the projects of some spefic user,
where the project name (field "project") contains (for sample) the word
"ojb".
 
I tried to use a criteria, some like that:
 
         Criteria c = new Criteria();
         c.addEqualsTo( "\"SIM_USERPROJECT\".fkuser", user.getPkUser()
);
         c.addLike("project","%ojb%");
 
         Query q = QueryFactory.newQuery( Project.class, c, true );
         it = broker.getIteratorByQuery( q );
 
This make some like cartesian-product and return all projects. I tried
to add the ON clause, like "c.addEqualsTo("\"SIM_USERPROJECT\".fkuser,
"\"SIM_USER\".pkuser);" and
"c.addEqualsTo("\"SIM_ USERPROJECT \".fkproject,
"\"SIM_PROJECT\".pkproject);" but it didn't work.
 
The website http://db.apache.org/ojb/docu/guides/query.html#joins
contains one similar sample and I'm not understanding what is wrong.
 
Thank u
 
Arivan
 
The model used:
 
<!-- USER -->
<class-descriptor class="br.com.simage.models.User"
table='"SIM_USUARIO"'>
    <field-descriptor name="name" column=" name" jdbc-type="VARCHAR"
length="50"></field-descriptor>
    <field-descriptor name="pkUser"  column=" pkuser "  jdbc-
type="INTEGER" primarykey="true" autoincrement="true"
sequence-        name="seq_user"></field-descriptor>
 
  <collection-descriptor
     name="projects"
     collection-
class="org.apache.ojb.broker.util.collections.ManageableArrayList"
     element-class-ref="br.com.simage.models.Project"
             orderby="project" 
             sort="ASC" 
     auto-retrieve="true"
     auto-update="true"
     indirection-table='"SIM_USERPROJETCT"'>
     <fk-pointing-to-this-class column="fkUser"/>
     <fk-pointing-to-element-class column="fkPoject"/>
  </collection-descriptor></class-descriptor>
 
<!-- PROJECT -->
<class-descriptor class="br.com.simage.models.Project"
table='"SIM_PROJECT"'>
    <field-descriptor name="project" column="project"
jdbc-type="VARCHAR" length="250"></field-descriptor>
   <field-descriptor name="pkProject"  column="pkproject"
jdbc-type="INTEGER" primarykey="true" autoincrement="true"
sequence-name="seq_project"></field-descriptor>
            <collection-descriptor
                        name="users"
                        collection-
class="org.apache.ojb.broker.util.collections.ManageableArrayList"
                        element-class-ref="br.com.simage.models.User"
                        orderby="nome" 
                        sort="ASC" 
                        indirection-table='"SIM_USERPROJECT"'>
                        <fk-pointing-to-this-class column="fkProject"/>
                        <fk-pointing-to-element-class column="fkUser"/>
            </collection-descriptor>
</class-descriptor>