Try
Criteria c = new Criteria();
c.addEqualsTo( "fkuser", user.getPkUser());
c.addLike("project","%ojb%");
Query q = QueryFactory.newQuery( Project.class, c, true );
it = broker.getIteratorByQuery( q );
In this case, you didn't have to do a join. If you DID want to do a join -
say, to find all of the projects with a name containing "ojb", for user with
a name of Arivan you'd do
Criteria c = new Criteria();
c.addEqualsTo( "users.name", "Arivan");
c.addLike("project","%ojb%");
Query q = QueryFactory.newQuery( Project.class, c, true );
it = broker.getIteratorByQuery( q );
Typically, you should use the reference and attribute names of your classes,
not the table/column names (although you can refer to column names should
you need to).
Cheers,
Charles.
-----Original Message-----
From: nwbr [mailto:[EMAIL PROTECTED]
Sent: 09 June 2005 22:47
To: 'OJB Users List'
Subject: 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>
___________________________________________________________
HPD Software Ltd. - Helping Business Finance Business
Email terms and conditions: www.hpdsoftware.com/disclaimer
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]