-->
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: Strange HQL-behavior by retrieving map-value
PostPosted: Wed Dec 22, 2004 6:31 am 
Newbie

Joined: Wed Nov 10, 2004 12:27 pm
Posts: 10
Location: Düsseldorf, Germany
Hallo,

I have a quite strange problem with my HQL-Query. Within my DAO I would like to make use of a map to restrict my results. When I construct the query as below, I get no results:

String queryString = "from Category c "
+ where c.description.titles[:code] = :title";
Query q = session.createQuery(queryString);
q.setText("code", "de");
q.setText("title", title);

But when I try the following, everything works as expected:

String queryString = "from Category c "
+ where c.description.titles['de'] = :title";
Query q = session.createQuery(queryString);
q.setText("title", title);

Any ideas on this topic? Am I missing something completely?
Cheers
Christian

Hibernate version: 2.1.7


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 23, 2004 4:01 am 
Newbie

Joined: Wed Nov 10, 2004 12:27 pm
Posts: 10
Location: Düsseldorf, Germany
Perhaps I am completely overseeing something elemental but I still can't get rid of this problem. Has anybody an idea?

Christian


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 23, 2004 4:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
how does the underlying sql looks like ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 23, 2004 7:23 am 
Newbie

Joined: Wed Nov 10, 2004 12:27 pm
Posts: 10
Location: Düsseldorf, Germany
Well the underlying SQL looks like the following:

String queryString = "from Category c where c.typeString = :type and c.description.titles[:code] = :title";

Query q = session.createQuery(queryString);
q.setText("type", CategoryType.ALPHABETICAL.getName());
q.setText("title", title);
q.setText("code", "de");

Category c = q.uniqueResult();

SQL:
====
select category0_.ENTITY_ID as ENTITY_ID, category0_.PARENT_CATEGORY as PARENT_C8_, category0_.CATEGORY_TYPE as CATEGORY9_, category0_.CREATION_DATE as CREATION3_, category0_.MODIFICATION_DATE as MODIFICA4_, category0_.LAST_EDITOR_ID as LAST_EDI5_, category0_.DEFAULT_LANGUAGE_ID as DEFAULT_6_, category0_.STATUS as STATUS from ENTITY category0_, TITLES titles1_ where category0_.TYPE='CATEGORY' and ((category0_.CATEGORY_TYPE=? )and(titles1_.TITLE=? and category0_.ENTITY_ID=titles1_.ENTITY_ID and titles1_.ISO_LANG_CODE = ?))

The return value of the query is null. If I construct the query like this:

String queryString = "from Category c where c.typeString = :type and c.description.titles['de'] = :title";

Query q = session.createQuery(queryString);
q.setText("type", CategoryType.ALPHABETICAL.getName());
q.setText("title", title);

Category c = q.uniqueResult();

everything works fine. On q.uniqueResults() plenty of SQL-queries are generated, much to many to post in here. Reason for this is, that there are several Map-mappings and relationships queried for. Here is the underlying SQL:

select category0_.ENTITY_ID as ENTITY_ID, category0_.PARENT_CATEGORY as PARENT_C8_, category0_.CATEGORY_TYPE as CATEGORY9_, category0_.CREATION_DATE as CREATION3_, category0_.MODIFICATION_DATE as MODIFICA4_, category0_.LAST_EDITOR_ID as LAST_EDI5_, category0_.DEFAULT_LANGUAGE_ID as DEFAULT_6_, category0_.STATUS as STATUS from ENTITY category0_, TITLES titles1_ where category0_.TYPE='CATEGORY' and ((category0_.CATEGORY_TYPE=? )and(titles1_.TITLE=? and category0_.ENTITY_ID=titles1_.ENTITY_ID and titles1_.ISO_LANG_CODE = 'de'))

The queries are looking quite the same - as expected. Perhaps there is a problem with inserting "'" for the map key when replacing the named parameters?

Christian


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 23, 2004 9:29 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Don't use setText, use setString


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 23, 2004 9:38 am 
Newbie

Joined: Wed Nov 10, 2004 12:27 pm
Posts: 10
Location: Düsseldorf, Germany
Okay, but the use of setString() does not solve the problem


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 23, 2004 9:52 am 
Newbie

Joined: Wed Nov 10, 2004 12:27 pm
Posts: 10
Location: Düsseldorf, Germany
To solve this problem, I use a workaround now, where I set the query string manually like

String queryString = "from Category c "
+ "where c.typeString = :type and c.description.titles['"
+ "de" + "'] = :title";

Query q = session.createQuery(queryString);
q.setString("type", CategoryType.ALPHABETICAL.getName());
q.setString("title", title);

I know, it's not the best solution, but it works. I'm quite interested in the experiences of other hibernate users wether they have to face the same problem.

Christian


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.