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 Marcus Breese <ma...@breese.com> on 2003/07/29 08:37:18 UTC

Query limiting by m:n relationship

I'm sorry for asking what may be a silly question,  but is it possible 
to query the database using a Criteria that includes a field that is in 
a m:n relationship, but not intrinsically in the class.

For example:

class widget {
	Integer id
	String name

	Collection allCategories() (ojb.collection to widget_category)
}

class category {
	Integer id
	String name
	Integer parent_id
}

// indirection table/class
class widget_category {
	Integer widgetId
	Integer categoryId
}

With all of the associated tables and OJB mappings...

Is it possible to create a criteria that says "Give me all Widgets in 
Category X"?  Or is is possible to do a "query by example"?

-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=-
Marcus Breese                            mbreese@iupui.edu
IU School of Medicine              marcus@breese.com
Dept. of Biochemistry and Molecular Biology
Center for Medical Genomics / Grow Lab


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Query limiting by m:n relationship

Posted by Marcus Breese <ma...@breese.com>.
As it turns out, this has been covered here before...  so, just 
disregard this redundant question.

Answer, in case anyone wants to know, is to use a Criteria where you 
simply say:
	Criteria c = new Criteria()
	c.addEqualTo("allCategories.id","1");
	(or something similar...)

Sorry for the duplicate... : )

On Tuesday, July 29, 2003, at 01:37  AM, Marcus Breese wrote:

> I'm sorry for asking what may be a silly question,  but is it possible 
> to query the database using a Criteria that includes a field that is 
> in a m:n relationship, but not intrinsically in the class.
>
> For example:
>
> class widget {
> 	Integer id
> 	String name
>
> 	Collection allCategories() (ojb.collection to widget_category)
> }
>
> class category {
> 	Integer id
> 	String name
> 	Integer parent_id
> }
>
> // indirection table/class
> class widget_category {
> 	Integer widgetId
> 	Integer categoryId
> }
>
> With all of the associated tables and OJB mappings...
>
> Is it possible to create a criteria that says "Give me all Widgets in 
> Category X"?  Or is is possible to do a "query by example"?
>
> -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=-
> Marcus Breese                            mbreese@iupui.edu
> IU School of Medicine              marcus@breese.com
> Dept. of Biochemistry and Molecular Biology
> Center for Medical Genomics / Grow Lab
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=-
Marcus Breese                            mbreese@iupui.edu
IU School of Medicine              marcus@breese.com
Dept. of Biochemistry and Molecular Biology
Center for Medical Genomics / Grow Lab



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org