SQL IN() operator

Tag(s):

Here is an example of how you define a list of values in hibernate for the SQL IN() operator:

/*
 * Update the gender field of Person table where IDs are equal to 1, 21, 45
 */
Query oQuery = session.createSQLQuery("UPDATE Person SET gender=:gender WHERE id IN(:id_list)");
oQuery.setString("gender", "male");
oQuery.setParameterList("id_list", new Object[]{new Integer(1), new Integer(21), new Integer(45)});
int iRowCnt = oQuery.executeUpdate();