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.  [ 2 posts ] 
Author Message
 Post subject: querying map using [] semantics doesn't work in inner select
PostPosted: Tue Jul 27, 2004 4:28 pm 
Newbie

Joined: Tue Jun 01, 2004 12:33 pm
Posts: 6
Using Hibernate 2.1.2 here.

Briefly, the object I am querying for is a Document. It has a Metadata object, which contains a HashMap called 'data'. 'data' maps field names to AbstractMetadataValue objects.

The following query works and returns the desired object:

Code:
select d from Document d, AbstractMetadataValue amv where d.Metadata.data['description'] = amv and amv.persistableData like '%desc%'


It gives me the Documents that have a metadata value named 'description' that contains the string 'desc'.

However, the same query does not work within an inner select statement like this:

Code:
select distinct doc from Document doc where doc in (select d from Document d, AbstractMetadataValue amv where d.Metadata.data['description'] = amv and amv.persistableData like '%desc%')


I get the following stack trace, which appears to indicate that this syntax is not supported. Is there a reason why this query does not work? It seems like it ought to.

Quote:
net.sf.hibernate.QueryException: unexpected [ [select distinct doc from collective.mb.asset.Document doc where doc in (select d from collective.mb.asset.Document d, collective.asset.AbstractMetadataValue amv where d.Metadata.data['description'] = amv and amv.persistableData like '%desc%')]
net.sf.hibernate.QueryException: unexpected [ [select distinct doc from collective.mb.asset.Document doc where doc in (select d from collective.mb.asset.Document d, collective.asset.AbstractMetadataValue amv where d.Metadata.data['description'] = amv and amv.persistableData like '%desc%')]
at net.sf.hibernate.hql.WhereParser.token(WhereParser.java:186)
at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:123)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:293)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1530)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1501)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1491)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1483)
[/quote][/code]


Top
 Profile  
 
 Post subject: WhereParser throws Exception on '[' in inner queries
PostPosted: Wed Mar 23, 2005 2:56 pm 
Newbie

Joined: Tue Jun 01, 2004 12:33 pm
Posts: 6
It's been a number of months since I posted the original question in this thread and I've now come back to where the workaround I implemented is really bothering me. We are now using Hibernate 2.1.8 and the problem persists.

So I did some debugging in the Hibernate source and found out why the WhereParser class is throwing an exception when it sees the '[' character inside of the inner select query. The details (as I see them) are posted below.

I modified the code just to test out my theory and indeed the problem was fixed. My question is should I post a potential patch or is Hibernate 2.1.X dead and should I just switch over to Hibernate 3.0 and hope that the problem is fixed there?

More details available upon request, I just didn't want to overdo it here if it wasn't really necessary.

Thanks

----------------------

Details:

The token() method in WhereParser just builds up a String containing the text within the parens that mark the inner query. It then constructs a new QueryTranslator to parse that string.

When the original query parser hits that [, it should ignore it because it's part of the inner select, which is going to be handled later by the 2nd query parser. But it doesn't. It sees that the bracket is out of place and throws an exception.

My proposed fix is to wrap the lines dealing with path continuations within a conditional to ensure that we're not in a sub select. The fix appeared to work (it solved my problem) and the unit tests ran successfully.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.