From: Jon L. <jon...@xe...> - 2002-07-02 13:06:34
|
Thanks Gavin, Yes, that will work... That select was in some legacy code and I was just trying to replace it like it was. (To many hours staring at other people code :-) I guess I owe you a beer for saving me some time... I like the idea of your select with the [] syntax. I'll take a look to see if that would reduce the number of classes I need somewhere, and if so I'll try to add it. I'll keep you posted... Cheers, Jon... ----- Original Message ----- From: <Gavin_King/Cirrus%CI...@ci...> To: "Jon Lipsky" <jon...@xe...> Cc: <hib...@li...> Sent: Tuesday, July 02, 2002 2:32 AM Subject: Re: [Hibernate-devel] Is this type of query possible? > > > Basically, there is a parent table ("foo" in my example above) and > > there is list of attributes for a particular foo object > > (called "foo_attr") in my example above. I want to find all Foo's > > where it have an attribute "attribute1" equal to "value1" and an > > attribute "attribute2" equal to "value2". > > > > So, is this something I will have to implement (and if so, are there > > suggestions on the syntax of the query), or does this already exist? > > I *think* I understand what you are trying to do though I'm not sure > why you used a nested subselect so perhaps there is something I'm > missing. > > If you were to map this as a (nested) one-to-many set of Attibutes, I > think you can express this as: > > select foo > from foo in class Foo, att1 in foo.attributes, att2 in foo.attributes > where att1.name = 'attribute1' and att1.value = 'value1' > and att2.name='attribute2' and att2.value = 'value2' > > (though the generated SQL here contains no subselects). What I would > love to be able to do would be to map this instead as a (nested) map > with String index + element and then express the query as: > > from foo in class Foo > where foo.attributes['attribute1']='value1' > and foo.attributes['attribute2']='value2' > > However, the [] indexing syntax is not implemented. The advantage of > this approach is we don't have to invent this whole new class called > Attribute to contain name/value pairs. If someone wants to implement > [], that would be wonderful - but it might be nontrivial. > > Does that help? > |