Hibernate version: 2.1.7c
Name and version of the database you are using: Firebird 1.5.2
Our domain model has 3 main objects, Printer, Feature and Setting.
Each Printer has a Map named "features" whose keys are Strings that
represent a type of Feature and whose values are the corresponding Feature
objects. For example, a Printer's map might contain "NetworkFeature"
which maps to a (derived) NetworkFeature object and "ApplicationFeature"
which maps to an ApplicationFeature object.
Similarly, each Feature has a Map named "settings" whose keys are Strings
that represent the name of a Setting and whose values are Strings that are
the value of the setting. For example, a NetworkFeature's map may contain
"contactName" which maps to "John Smith".
We have mapped the Feature hierarchy as joined subclasses, and we've
created mappings for the Printer.features and Feature.settings Maps like
this:
<map
name="features"
table="PRINTERS_HAVE_FEATURE"
lazy="false"
inverse="false"
cascade="save-update">
<key column="FK_PRINTER"/>
<index column="FEATURENAME" type="string" length="50" />
<many-to-many class="com.lexmark.workflow.framework.domain.printer.model.Feature"/>
</map>
We can create object graphs and save them, and some simple queries work,
but when I try to "AND" together two things in the WHERE clause, the query
fails.
An example of a query that works is:
select p from Printer p join p.features as f join f.settings as s where
(f.name = 'NetworkFeature' and s.name='contactName' and s.value='John
Smith')
When I execute this query, it finds about 6 objects whose
NetworkFeature.contactName are 'John Smith'. I can also see that about
half the objects have an ApplicationFeature.pharosServer of 'pharos2', but
when I try to narrow the search to just those objects using the query
below, it fails:
select p from Printer p join p.features as f join f.settings as s where
(f.name = 'NetworkFeature' and s.name='contactName' and s.value='John
Smith') and (f.name = 'ApplicationFeature' and s.name='pharosServer' and s.value='pharos2')
Q1: Am I doing something obviously wrong here?
Q2: Is there a better way to address the Maps in the query? I haven't
found an example of a query where I can use a syntax like this:
where p.features[NetworkFeature].settings[contactName] = 'John Smith'
Any help appreciated!
-Jeff
|