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 "Sean P. Hawkins" <sp...@steelpagoda.com> on 2004/01/24 17:12:09 UTC
Proper way to query non-decomposed M-to-N association
Hello all,
I have an application that has people (and subtypes of people)
containing addresses. I am trying to construct a query to return all
people with a city like "x". So far, I've been less than successful.
My repository looks like this:
<class-descriptor
class="com.steelpagoda.fist.model.Person">
<extent-class class-ref="com.steelpagoda.fist.model.StudentImpl" />
</class-descriptor>
<class-descriptor
class="com.steelpagoda.fist.model.PersonImpl"
table="people"
>
<field-descriptor
name="id"
column="pid"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
/>
... snip ...
<collection-descriptor
name="addresses"
element-class-ref="com.steelpagoda.fist.model.AddressImpl"
refresh="true"
auto-retrieve="true"
auto-update="false"
indirection-table="peopleaddresses"
>
<fk-pointing-to-this-class column="pid"/>
<fk-pointing-to-element-class column="addressid"/>
</collection-descriptor>
... snip ...
</class-descriptor>
<class-descriptor
class="com.steelpagoda.fist.model.StudentImpl"
table="students"
>
<reference-descriptor name="super"
class-ref="com.steelpagoda.fist.model.PersonImpl"
>
<foreignkey field-ref="id" />
</reference-descriptor>
<field-descriptor
name="id"
column="pid"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
/>
... snip ...
</class-descriptor>
<class-descriptor
class="com.steelpagoda.fist.model.AddressImpl"
table="addresses"
>
<field-descriptor
name="id"
column="addressid"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
/>
<field-descriptor
name="company"
column="company"
jdbc-type="VARCHAR"
/>
<field-descriptor
name="line1"
column="line1"
jdbc-type="VARCHAR"
/>
<field-descriptor
name="line2"
column="line2"
jdbc-type="VARCHAR"
/>
<field-descriptor
name="line3"
column="line3"
jdbc-type="VARCHAR"
/>
<field-descriptor
name="city"
column="city"
jdbc-type="VARCHAR"
/>
<field-descriptor
name="state"
column="stateprov"
jdbc-type="VARCHAR"
/>
<field-descriptor
name="postalCode"
column="postalcode"
jdbc-type="VARCHAR"
/>
<field-descriptor
name="country"
column="country"
jdbc-type="VARCHAR"
/>
<collection-descriptor
name="residents"
element-class-ref="com.steelpagoda.fist.model.PersonImpl"
auto-retrieve="true"
auto-update="false"
indirection-table="peopleaddresses"
>
<fk-pointing-to-this-class column="addressid"/>
<fk-pointing-to-element-class column="pid"/>
</collection-descriptor>
<collection-descriptor
name="tags"
element-class-ref="com.steelpagoda.fist.model.PersonAddressTag"
orderby="personId"
sort="ASC"
>
<inverse-foreignkey field-ref="addressId"/>
</collection-descriptor>
</class-descriptor>
<class-descriptor
class="com.steelpagoda.fist.model.PersonAddressTag"
table="peopleaddresses"
>
<field-descriptor
name="personId"
column="pid"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="false"
/>
<field-descriptor
name="addressId"
column="addressid"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="false"
/>
<field-descriptor
name="tag"
column="tag"
jdbc-type="VARCHAR"
primarykey="true"
autoincrement="false"
/>
</class-descriptor>
I can query on any person field and get the expected behavior with
regard to addresses contained in the addresses collection (e.g. the
correct addresses are associated with the appropriate people.) If I try
the following code, however:
Criteria crit = new Criteria();
crit.addLike("addresses.city", "%something%");
QueryByCriteria q = QueryFactory.newQuery(Person.class, crit, false);
retVal = pb.getCollectionByQuery(q);
I either get everyone or no one returned. Obviously, the generated SQL
is missing a clause to limit the cartesian product on the join. What am
I doing wrong? Any help would be greatly appreciated. A similar query
through the ODMG interface behaved in the same way.
Thanks in advance.
Sean P. Hawkins
Steel Pagoda Information Systems, Inc.
www.steelpagoda.com
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Proper way to query non-decomposed M-to-N association
Posted by "Sean P. Hawkins" <sp...@steelpagoda.com>.
Jakob,
That worked like a charm. Thank you.
--Sean
Jakob Braeuchi wrote:
> hi sean,
>
> have you tried adding a collection-descriptor 'addresses' to
> StudentImpl as well ? ojb does not support inheritance of descriptors.
>
> hth
> jakob
>
> Sean P. Hawkins wrote:
>
>> Hello all,
>>
>> I have an application that has people (and subtypes of people)
>> containing addresses. I am trying to construct a query to return all
>> people with a city like "x". So far, I've been less than successful.
>>
>> My repository looks like this:
>>
>> <class-descriptor
>> class="com.steelpagoda.fist.model.Person">
>> <extent-class class-ref="com.steelpagoda.fist.model.StudentImpl" />
>> </class-descriptor>
>>
>> <class-descriptor
>> class="com.steelpagoda.fist.model.PersonImpl"
>> table="people"
>> >
>> <field-descriptor
>> name="id"
>> column="pid"
>> jdbc-type="INTEGER"
>> primarykey="true"
>> autoincrement="true"
>> />
>>
>> ... snip ...
>>
>> <collection-descriptor
>> name="addresses"
>> element-class-ref="com.steelpagoda.fist.model.AddressImpl"
>> refresh="true"
>> auto-retrieve="true"
>> auto-update="false"
>> indirection-table="peopleaddresses"
>> >
>> <fk-pointing-to-this-class column="pid"/>
>> <fk-pointing-to-element-class column="addressid"/>
>> </collection-descriptor>
>>
>> ... snip ...
>>
>> </class-descriptor>
>>
>>
>> <class-descriptor
>> class="com.steelpagoda.fist.model.StudentImpl"
>> table="students"
>> >
>> <reference-descriptor name="super"
>> class-ref="com.steelpagoda.fist.model.PersonImpl"
>> >
>> <foreignkey field-ref="id" />
>> </reference-descriptor>
>>
>> <field-descriptor
>> name="id"
>> column="pid"
>> jdbc-type="INTEGER"
>> primarykey="true"
>> autoincrement="true"
>> />
>> ... snip ...
>>
>> </class-descriptor>
>>
>> <class-descriptor
>> class="com.steelpagoda.fist.model.AddressImpl"
>> table="addresses"
>> >
>>
>> <field-descriptor
>> name="id"
>> column="addressid"
>> jdbc-type="INTEGER"
>> primarykey="true"
>> autoincrement="true"
>> />
>> <field-descriptor
>> name="company"
>> column="company"
>> jdbc-type="VARCHAR"
>> />
>> <field-descriptor
>> name="line1"
>> column="line1"
>> jdbc-type="VARCHAR"
>> />
>> <field-descriptor
>> name="line2"
>> column="line2"
>> jdbc-type="VARCHAR"
>> />
>> <field-descriptor
>> name="line3"
>> column="line3"
>> jdbc-type="VARCHAR"
>> />
>> <field-descriptor
>> name="city"
>> column="city"
>> jdbc-type="VARCHAR"
>> />
>> <field-descriptor
>> name="state"
>> column="stateprov"
>> jdbc-type="VARCHAR"
>> />
>> <field-descriptor
>> name="postalCode"
>> column="postalcode"
>> jdbc-type="VARCHAR"
>> />
>> <field-descriptor
>> name="country"
>> column="country"
>> jdbc-type="VARCHAR"
>> />
>> <collection-descriptor
>> name="residents"
>> element-class-ref="com.steelpagoda.fist.model.PersonImpl"
>> auto-retrieve="true"
>> auto-update="false"
>> indirection-table="peopleaddresses"
>> >
>> <fk-pointing-to-this-class column="addressid"/>
>> <fk-pointing-to-element-class column="pid"/>
>> </collection-descriptor>
>> <collection-descriptor
>> name="tags"
>> element-class-ref="com.steelpagoda.fist.model.PersonAddressTag"
>> orderby="personId"
>> sort="ASC"
>> >
>> <inverse-foreignkey field-ref="addressId"/>
>> </collection-descriptor>
>> </class-descriptor>
>>
>> <class-descriptor
>> class="com.steelpagoda.fist.model.PersonAddressTag"
>> table="peopleaddresses"
>> >
>> <field-descriptor
>> name="personId"
>> column="pid"
>> jdbc-type="INTEGER"
>> primarykey="true"
>> autoincrement="false"
>> />
>>
>> <field-descriptor
>> name="addressId"
>> column="addressid"
>> jdbc-type="INTEGER"
>> primarykey="true"
>> autoincrement="false"
>> />
>> <field-descriptor
>> name="tag"
>> column="tag"
>> jdbc-type="VARCHAR"
>> primarykey="true"
>> autoincrement="false"
>> />
>> </class-descriptor>
>>
>> I can query on any person field and get the expected behavior with
>> regard to addresses contained in the addresses collection (e.g. the
>> correct addresses are associated with the appropriate people.) If I
>> try the following code, however:
>>
>> Criteria crit = new Criteria();
>> crit.addLike("addresses.city", "%something%");
>> QueryByCriteria q = QueryFactory.newQuery(Person.class, crit, false);
>> retVal = pb.getCollectionByQuery(q);
>>
>> I either get everyone or no one returned. Obviously, the generated
>> SQL is missing a clause to limit the cartesian product on the join.
>> What am I doing wrong? Any help would be greatly appreciated. A
>> similar query through the ODMG interface behaved in the same way.
>>
>> Thanks in advance.
>>
>> Sean P. Hawkins
>> Steel Pagoda Information Systems, Inc.
>> www.steelpagoda.com
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Proper way to query non-decomposed M-to-N association
Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi sean,
have you tried adding a collection-descriptor 'addresses' to StudentImpl as well
? ojb does not support inheritance of descriptors.
hth
jakob
Sean P. Hawkins wrote:
> Hello all,
>
> I have an application that has people (and subtypes of people)
> containing addresses. I am trying to construct a query to return all
> people with a city like "x". So far, I've been less than successful.
>
> My repository looks like this:
>
> <class-descriptor
> class="com.steelpagoda.fist.model.Person">
> <extent-class class-ref="com.steelpagoda.fist.model.StudentImpl" />
> </class-descriptor>
>
> <class-descriptor
> class="com.steelpagoda.fist.model.PersonImpl"
> table="people"
> >
> <field-descriptor
> name="id"
> column="pid"
> jdbc-type="INTEGER"
> primarykey="true"
> autoincrement="true"
> />
>
> ... snip ...
>
> <collection-descriptor
> name="addresses"
> element-class-ref="com.steelpagoda.fist.model.AddressImpl"
> refresh="true"
> auto-retrieve="true"
> auto-update="false"
> indirection-table="peopleaddresses"
> >
> <fk-pointing-to-this-class column="pid"/>
> <fk-pointing-to-element-class column="addressid"/>
> </collection-descriptor>
>
> ... snip ...
>
> </class-descriptor>
>
>
> <class-descriptor
> class="com.steelpagoda.fist.model.StudentImpl"
> table="students"
> >
> <reference-descriptor name="super"
> class-ref="com.steelpagoda.fist.model.PersonImpl"
> >
> <foreignkey field-ref="id" />
> </reference-descriptor>
>
> <field-descriptor
> name="id"
> column="pid"
> jdbc-type="INTEGER"
> primarykey="true"
> autoincrement="true"
> />
> ... snip ...
>
> </class-descriptor>
>
> <class-descriptor
> class="com.steelpagoda.fist.model.AddressImpl"
> table="addresses"
> >
>
> <field-descriptor
> name="id"
> column="addressid"
> jdbc-type="INTEGER"
> primarykey="true"
> autoincrement="true"
> />
> <field-descriptor
> name="company"
> column="company"
> jdbc-type="VARCHAR"
> />
> <field-descriptor
> name="line1"
> column="line1"
> jdbc-type="VARCHAR"
> />
> <field-descriptor
> name="line2"
> column="line2"
> jdbc-type="VARCHAR"
> />
> <field-descriptor
> name="line3"
> column="line3"
> jdbc-type="VARCHAR"
> />
> <field-descriptor
> name="city"
> column="city"
> jdbc-type="VARCHAR"
> />
> <field-descriptor
> name="state"
> column="stateprov"
> jdbc-type="VARCHAR"
> />
> <field-descriptor
> name="postalCode"
> column="postalcode"
> jdbc-type="VARCHAR"
> />
> <field-descriptor
> name="country"
> column="country"
> jdbc-type="VARCHAR"
> />
> <collection-descriptor
> name="residents"
> element-class-ref="com.steelpagoda.fist.model.PersonImpl"
> auto-retrieve="true"
> auto-update="false"
> indirection-table="peopleaddresses"
> >
> <fk-pointing-to-this-class column="addressid"/>
> <fk-pointing-to-element-class column="pid"/>
> </collection-descriptor>
> <collection-descriptor
> name="tags"
> element-class-ref="com.steelpagoda.fist.model.PersonAddressTag"
> orderby="personId"
> sort="ASC"
> >
> <inverse-foreignkey field-ref="addressId"/>
> </collection-descriptor>
> </class-descriptor>
>
> <class-descriptor
> class="com.steelpagoda.fist.model.PersonAddressTag"
> table="peopleaddresses"
> >
> <field-descriptor
> name="personId"
> column="pid"
> jdbc-type="INTEGER"
> primarykey="true"
> autoincrement="false"
> />
>
> <field-descriptor
> name="addressId"
> column="addressid"
> jdbc-type="INTEGER"
> primarykey="true"
> autoincrement="false"
> />
> <field-descriptor
> name="tag"
> column="tag"
> jdbc-type="VARCHAR"
> primarykey="true"
> autoincrement="false"
> />
> </class-descriptor>
>
> I can query on any person field and get the expected behavior with
> regard to addresses contained in the addresses collection (e.g. the
> correct addresses are associated with the appropriate people.) If I try
> the following code, however:
>
> Criteria crit = new Criteria();
> crit.addLike("addresses.city", "%something%");
> QueryByCriteria q = QueryFactory.newQuery(Person.class, crit, false);
> retVal = pb.getCollectionByQuery(q);
>
> I either get everyone or no one returned. Obviously, the generated SQL
> is missing a clause to limit the cartesian product on the join. What am
> I doing wrong? Any help would be greatly appreciated. A similar query
> through the ODMG interface behaved in the same way.
>
> Thanks in advance.
>
> Sean P. Hawkins
> Steel Pagoda Information Systems, Inc.
> www.steelpagoda.com
>
>
>
> ---------------------------------------------------------------------
> 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