I am still new to OJB and I was just wondering why in the suggestion
code below you chose
crit.addLike( "state", "somestate" );
Rather than something like
Crit.addEqualTo("state", "somestate");
Or even
Crit.addColumnEqualTo("state", "somestate");
Sorry if this is a stupid question, but I just was wondering why?
Roman
-----Original Message-----
From: Danilo Tommasina [mailto:[EMAIL PROTECTED]
Sent: Tuesday, November 23, 2004 04:44
To: OJB Users List
Subject: Re: Unique query without using primary key?
A ReportQueryByCriteria should do the job:
something like this:
Criteria crit = new Criteria();
crit.addLike( "state", "somestate" );
crit.addLike( "<ref To SearchWords>.searchword", "somesearchword" );
ReportQueryByCriteria query = new ReportQueryByCriteria(
SearchKeys.class, new String [] { "sid" }, crit, true );
PersistenceBroker pb = null;
try {
pb = PersistenceBrokerFactory.defaultPersistenceBroker();
ArrayList results = new ArrayList();
for ( Iterator resultsIt = pb.getReportQueryIteratorByQuery( query );
resultsIt.hasNext(); ) {
results.add( ((Object []) resultsIt.next())[ 0 ] );
}
// The results ArrayList now contains all the ids you need
// Note: always extact the values from the Iterator before closing
the broker.
} catch ( Exception e ) {
// Do exception handling
} finally {
if ( pb != null ) {
pb.close();
}
}
Replace <ref To SearchWords> with the reference path defined in your
repository.xml I didn't tested the code, so there are probably syntax
errors...
> I am not getting this. I need a nudge in the right direction.
>
> I want to do this query:
> select distinct sk.sid from searchkeys sk, searchwords sw
> where sw.searchword="somesearchword"
> sw.sid = sk.sid
> sk.state="somestate";
>
> table searchkeys:
> sid <-- unique PK
> state
>
> table searchwords:
> swid <-- unique PK I wish OJB didn't
require
> sid <-- sid in searchkey table
> searchword
>
> searchkeys and searchwords having a 1:n relationship.
>
>
> Right now I both tables mapped according to their characteristics
which I have done many times before. In the past I have always wanted
the primary keys and full records.
>
> Here I don't want the full records or mapping, but just a collection
of the unique sid. I would prefer not to get the full records and I
only require this for read and not write. Imagine I am doing a keyword
search and I just want to know which services match the search criteria.
>
> Can anybody nudge me in the right direction? Would be great to get
past this problem. I am trying to inprove the searching on my live OJB
used site by including parts of the Lucene project, but need to be able
to do this for it to work.
>
> Thanks lots.
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]