-->
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.  [ 1 post ] 
Author Message
 Post subject: HQL-StringIndexOfBoundException- when Using Multiple OR
PostPosted: Fri Feb 08, 2013 1:00 am 
Newbie

Joined: Fri Feb 08, 2013 12:30 am
Posts: 1
Hi,

I am using a Hibernate Query to fetch the list of employees and then this list is used to fetch extended details.

List<Long> employeeList;

String test=(" Select * from table_name where company="ABC" and employee id IN (:employee)");

Query query=session.createquery(test);
query.setParameterList("employee",employeeList);

The problem i had with this was oracle does not accept more than 1000 values in IN clause and had a run time exception.

Now to overcome this i am splitting the employeeList and trying to pass it as smaller list but with OR inbetween each list like

String test=(" Select * from table_name where company="ABC" and( employee id IN(:e0) OR employee id IN(:e1) OR employee id IN(:e2))");

Note: the list might have any number of smaller list as employeelist is dynamic so "e0".."e1" might be dynamic.

Query query=session.createquery(test);

now i am passing values using for loop

int counter=0;

for(int i=0;i<employee.size();i++)
{
String param="e"+counter;
query.setParameterList(param,employee.get(i);
counter++;
}

here employee is list which is having smaller list.

ArrayList<ArrayList<Long>> employee=new ArrayList<ArrayList<Long>>();

the real problem is if i pass values less than 50 in each smaller list hibernate parses it and return the list. If each list has more than 50 elements hibernate throws for following exceptions.

java.lang.StringIndexOutOfBoundsException: String index out of range: 1417
at java.lang.String.charAt(String.java:686)
at org.hibernate.util.StringHelper.replace(StringHelper.java:119)
at org.hibernate.util.StringHelper.replace(StringHelper.java:123)
at org.hibernate.impl.AbstractQueryImpl.expandParameterList(AbstractQueryImpl.java:773)
at org.hibernate.impl.AbstractQueryImpl.expandParameterLists(AbstractQueryImpl.java:742)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)

Also i cannot more than 150 OR in query. then again hibernate throws the same exception.

Please help me out on this and why hibernate throws this exception.

Thanks,
Shivraj


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

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.