• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pass a string array to HQL Query

 
Amith Bhavikatti
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I have a String array and i have to pass it has a parameter to Hibernate.hbm.xml file where my code looks like this:

String[] columns=new String[deleteList.size()];//String Array

Query q = session.getNamedQuery("deleteAssignmentByLetter").setParameterList("assignmentIDD",columns);//Calling the query from Hibernate.cfg.xml file

Hibernate.hbm.xml File Query:

<query name="deleteAssignmentByLetter"><![CDATA[
delete from AssignmentByLetter where assignmentID in (:assignmentIDD);
]]></query>

Please suggest me whether this is right or wrong?
How to a string array in ParameterList??

Thanks in Advance
 
Angel Taveras
Ranch Hand
Posts: 84
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi amithbn, could you post the error that it's showing?
 
Amith Bhavikatti
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Angel,

Actually till now i am just doing ant and building the project,because till now client did not told to implement it on their environment.till now build is successfull but i am confused in passing string array.

Whether i have to pass it like this to HQL or what?
columns[] or columns
Please give me suggestion just to pass a string array in the parameterlist..

Thanks in Advance
 
Angel Taveras
Ranch Hand
Posts: 84
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to your example above you have a collection. You can pass it as is, you don't have to convert it to an Array. Referring to the question at hand, you only need to now that the elements in the parametersList must be of the same type or belong to the same interface that it's known to hibernate and must match the type of the property that you're querying to. Meaning that if you are passing an array of String then the property that you're querying it's a String.

Regards,
[ December 11, 2008: Message edited by: Angel Taveras ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic