-->
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.  [ 6 posts ] 
Author Message
 Post subject: StringIndexOutOfBoundsException when using named HQL query
PostPosted: Fri Jul 22, 2005 5:02 am 
Newbie

Joined: Wed Apr 13, 2005 10:55 am
Posts: 3
Hello.

I have a problem when trying to use a named HQL query. I get a StringIndexOutOfBoundsException when trying to list the query.
The error (only in the browser btw, not in the console) is:

java.lang.StringIndexOutOfBoundsException: String index out of range: -1


My java code is:

Query q = session.getNamedQuery("findMessageByMailboxIdAndStatus");
q.setParameter("mailboxId", mailboxId+"");
q.setParameterList("statuses", params);
q.setMaxResults(pageSize);
q.setFirstResult(pageSize * pageNr);
List messages = q.list(); <- this is where the exception is thrown

The parameter known as 'statuses' is a list with Integers. The query definition itself is as follows (irrelevant stuff omitted):

<hibernate-mapping>
<class name="com.veritate.inbound.model.Message" table="messages">
.....
</class>

<sql-query name="findMessageByMailboxIdAndStatus"><![CDATA[
from Message as message where message.mailbox.id = :mailboxId
and message.status in (:statuses) order by message.created desc
]]>
</sql-query>


</hibernate-mapping>


What am I doing wrong?

stuff I use:
Hibernate 2.1.8
Java 1.4
Resin 3.0.13


Top
 Profile  
 
 Post subject: Re: StringIndexOutOfBoundsException when using named HQL que
PostPosted: Fri Jul 22, 2005 5:28 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
ronaldpieterse wrote:
Query q = session.getNamedQuery("findMessageByMailboxIdAndStatus");
q.setParameter("mailboxId", mailboxId+"");
q.setParameterList("statuses", params);
q.setMaxResults(pageSize);
q.setFirstResult(pageSize * pageNr);
List messages = q.list(); <- this is where the exception is thrown

q.setParameter("mailboxId", mailboxId+"");
I wonder what you're trying to do here. Don't know if this is related to your exception.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2005 6:33 am 
Newbie

Joined: Wed Apr 13, 2005 10:55 am
Posts: 3
Sorry my mistake, that is changed to:

q.setParameter("mailboxId", new Integer(mailboxId));

This is not the problem btw, since I've minimises the statement as much as possible to

<sql-query name="findMessageByMailboxIdAndStatus">
<![CDATA[from Message as message]]>
</sql-query>

Must be something else...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2005 7:24 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
please provide the Stacktrace ... it will make it easier to help.

And second, have a look at page 105 in the reference PDF. I'm not quite sure if you can have an "sql-query" without "select" etc. ...
My HiA is not available at the moment so i'm not able to look it up there ..

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2005 7:25 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
sorry ... (not my day i think) ...

you can look at page 74, too ... there's the description of how to write "named querys" ...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2005 7:51 am 
Newbie

Joined: Wed Apr 13, 2005 10:55 am
Posts: 3
ok, I found it finally. appearantly I should have used <query...> instead of <sql-query...>.

Quote:
And second, have a look at page 105 in the reference PDF. I'm not quite sure if you can have an "sql-query" without "select" etc. ...

yes, you can. well, in <query...> you can anyway...

I was under the impression that <query...> was deprecated and replaced by <sql-query...>.
My mistake then...

Thanx for all the replies, guys. C U Next time!


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