-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Help with queries against Maps
PostPosted: Wed May 04, 2005 1:34 pm 
Beginner
Beginner

Joined: Wed Feb 23, 2005 11:29 am
Posts: 26
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.