0

When we tried to retrieve data for a arraylist, we are iterating each row and then we are using fetch query.is there any other iteration row in hibernate template or sql

for (RequestObjRel reqObjRel : requestObjRelList) {

    String sqlQuery = "from Ce where cerId = '"
            + reqObjRel.getCed()
            + "' and trbr = "
            + reqObjRel.getCNbr();
    List<Certificate> certDetailList = dao
            .retrieveTableData(sqlQuery);
}

I could not find efficient way to retrieve data

Cœur
  • 37,241
  • 25
  • 195
  • 267
Vish
  • 867
  • 6
  • 19
  • 45

1 Answers1

2

You can make an HQL query that uses the IN clause and thus fetch multiple objects with one query. Something like:

from Foo foo where foo.id in (:fooIds)

Then you set the parameter on the Query object: query.setParameter("fooIds", listOfIds);

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • Thanks but can be pass more than one parameter. – Vish Oct 08 '11 at 10:53
  • the parameter is a `List` containing all the ids of your objects – Bozho Oct 08 '11 at 10:54
  • hmm..but if we composite primary key than what are available options – Vish Oct 08 '11 at 11:00
  • one last question how the above query will changed then – Vish Oct 08 '11 at 11:24
  • the query itself won't. It's just the list you pass that will contain the composite ids – Bozho Oct 08 '11 at 11:34
  • can you help me in eloborating answer.i have already put one [question](http://stackoverflow.com/questions/7769690/hibernate-hql-query-how-to-set-a-collection-as-a-named-parameter-of-a-query-wi) regarding this – Vish Oct 17 '11 at 07:57