-->
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.  [ 4 posts ] 
Author Message
 Post subject: Comparing a Map value against a String
PostPosted: Fri May 06, 2005 2:49 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

This seems like a simple thing but I can't seem to get it to work...

We have a main object Printer that has a Map of Feature objects, and the Feature objects in turn have a Map of Setting objects. The key in each map is the feature or setting name, so Printer might have one map entry whose key is the String "NetworkFeature" and whose value is a NetworkFeature object.

I can attach the *.hbm.xml if necessary later but I'm hoping you can just look at my query and see something dumb I'm doing :-)

I can execute THIS query, and I get back a list of the Printer objects that have a NetworkFeature element that has a contactName setting:

select distinct p from Printer p where p.features['NetworkFeature'].settings['contactName'] is not null);

But when I try to check for a specific contactName, like this:

select distinct p from Printer p where p.features['NetworkFeature'].settings['contactName']='John Smith'"

I get this exception:

org.springframework.jdbc.UncategorizedSQLException: (Hibernate operation): encountered SQLException [GDS Exception. 335544334. conversion error from string "John Smith"]; nested exception is org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544334. conversion error from string "John Smith"
org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544334. conversion error from string "John Smith"
at org.firebirdsql.jdbc.AbstractPreparedStatement.internalExecute(AbstractPreparedStatement.java:503)
at ...


I have tried replacing the 'John Smith' in the query with ? and :contactName and calling setString, setText, setParameter and all sorts of variations, but I can't seem to get this to work.

Any ideas???

-Jeff


Top
 Profile  
 
 Post subject: Aha!
PostPosted: Fri May 06, 2005 3:45 pm 
Beginner
Beginner

Joined: Wed Feb 23, 2005 11:29 am
Posts: 26
I got the following to work.

Code:
select distinct p from Printer p, NetworkFeature f, Setting s
where
   p.features['NetworkFeature'] = f and
   f.settings['contactName'] = s and
   s.value = 'John Smith'


-Jeff


Top
 Profile  
 
 Post subject: Aha #2
PostPosted: Fri May 06, 2005 4:41 pm 
Beginner
Beginner

Joined: Wed Feb 23, 2005 11:29 am
Posts: 26
I figure someday some other poor schmuck will be trying to figure this out, so I'll just append the next thing that person is likely to trip over, since I did.

In order to extend the query to match multiple feature/settings, I needed a separate feature and setting in the select.

Code:
select distinct p from
   Printer p, NetworkFeature f, Setting s, CopyFeature f2, Setting s2
where
   (p.features['NetworkFeature'] = f and f.settings['contactName'] = s and s.value = 'Nick Mudd')
and
   (p.features['CopyFeature'] = f2 and f2.settings['duplex'] = s2 and s2.value = 'Off')

I really feel like I earned my salary today :-)
-Jeff


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 9:48 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
One poor schmuck, right here :-D Thanks very much for this tip, it's EXACTLY what I needed RIGHT NOW.


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

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.