-->
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.  [ 7 posts ] 
Author Message
 Post subject: UnsupportedOperationException with HQL containing map key
PostPosted: Thu Apr 28, 2005 3:32 pm 
Beginner
Beginner

Joined: Tue Dec 09, 2003 5:59 pm
Posts: 25
Location: Los Angeles
I'm trying to run the following HQL query:
"from Foo where customProps['foo'] = 'bar'"
and I'm getting an UnsupportedOperationException. Looking at section 14.8 of the documentation, it looks like this should be possible. Any idea why it's not working?

Hibernate version: 3.0

Mapping documents:
<hibernate-mapping>
<class name="Foo">
<id name="id"><generator class="native"/></id>
<map name="customProps" lazy="false" cascade="all,delete-orphan">
<key><column name="id"/></key>
<map-key column="name" type="string"/>
<element column="value" type="string"/>
</map>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
session.createQuery(hql).list();

Full stack trace of any exception that occurs:
java.lang.UnsupportedOperationException
at org.hibernate.hql.ast.IdentNode.resolveIndex(IdentNode.java:24)
at org.hibernate.hql.ast.IndexNode.resolve(IndexNode.java:58)
at org.hibernate.hql.ast.FromReferenceNode.resolve(FromReferenceNode.java:87)
at org.hibernate.hql.ast.FromReferenceNode.resolve(FromReferenceNode.java:83)
at org.hibernate.hql.ast.HqlSqlWalker.processIndex(HqlSqlWalker.java:530)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:798)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:856)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:3261)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:2740)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1358)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:598)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:403)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:200)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:150)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:414)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:821)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:779)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.hmsonline.scorpio.server.MetadataRepositoryBean.executeQuery(MetadataRepositoryBean.java:901)
at com.hmsonline.scorpio.server.MetadataRepositoryBean.findFeeds(MetadataRepositoryBean.java:789)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:113)
at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:51)
at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:105)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:313)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:146)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:123)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
at org.jboss.ejb.plugins.CleanShutdownInterceptor.invoke(CleanShutdownInterceptor.java:264)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
at org.jboss.ejb.Container.invoke(Container.java:870)
at sun.reflect.GeneratedMethodAccessor448.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:144)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:249)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:642)
at org.jboss.invocation.jrmp.server.JRMPInvokerHA.invoke(JRMPInvokerHA.java:163)
at sun.reflect.GeneratedMethodAccessor79.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
at sun.rmi.transport.Transport$1.run(Transport.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:595)

Name and version of the database you are using:
Oracle 9


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 3:42 pm 
Beginner
Beginner

Joined: Tue Dec 09, 2003 5:59 pm
Posts: 25
Location: Los Angeles
I found that if I changed my HQL from
from Foo where customProps['foo'] = 'bar'
to
from Foo foo where foo.customProps['foo'] = 'bar'
then everything started working. Is this a bug?


Top
 Profile  
 
 Post subject: Where did you find the map key syntax in the first place?
PostPosted: Fri May 06, 2005 11:30 am 
Beginner
Beginner

Joined: Wed Feb 23, 2005 11:29 am
Posts: 26
I've been looking all over for the syntax that you mentioned in your reply, and now I'm close to being able to writing the query I've been fighting with- thanks!

Can you tell me, how did you know to use the foo.map['key'] syntax in the first place? I've read ALL of Hibernate in Action and several web searches, and until I just started reading through the forum, I don't remember seeing that syntax mentioned anywere.

I would appreciate any pointers to books, articles, sites - I think I'm going to become the resident Hibernate resource, so I gotta bone up!

-Jeff


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 06, 2005 11:36 am 
Beginner
Beginner

Joined: Tue Dec 09, 2003 5:59 pm
Posts: 25
Location: Los Angeles
It's in the main docs page at http://www.hibernate.org/hib_docs/v3/re ... ml_single/. Here's the example from that page:

select person from Person person, Calendar calendar
where calendar.holidays['national day'] = person.birthDay
and person.nationality.calendar = calendar

BTW, I filed a bug on this problem and it's been fixed in 3.0.3.


Top
 Profile  
 
 Post subject: Duh
PostPosted: Fri May 06, 2005 1:34 pm 
Beginner
Beginner

Joined: Wed Feb 23, 2005 11:29 am
Posts: 26
I feel dumb now. Guess I'll bookmark THAT page :-)

-Jeff


Top
 Profile  
 
 Post subject: I don't mean to bug you, but...
PostPosted: Fri May 06, 2005 2:53 pm 
Beginner
Beginner

Joined: Wed Feb 23, 2005 11:29 am
Posts: 26
I've posted this as its own topic, so if you're busy don't let me bug you...

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:

Code:
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:43 pm 
Beginner
Beginner

Joined: Wed Feb 23, 2005 11:29 am
Posts: 26
Got it to work with:

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  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.