Finally its resolved..
It was not an issue of JPA or hibernate.
When we followed the Wicket Example, to fetch the column values where checkbox is selected, we use a code:
String users = group.getDefaultModelObjectAsString();
Suppose, we've selected 3 records checkbox thus, we receive users as [user1, user2, user3]
As one can see, we are getting an extra space in each user name after user1 i.e. [user1,
<space>user2,
<space>user3]
This extra space is causing the error and not allowing the deletion of records from 2nd row onward.
I added a
trim() method before adding each user name in list like
Code:
List<String> users = new ArrayList<String>();
if(users.contains(",")){
users_no = users.split(",");
}
else
{
users_no = new String[1];
users_no[0]=users;
}
for(int ar_users=0;ar_users<users_no.length;ar_users++)
{
String user_name = users_no[ar_users];
if(user_name.contains("[")){
user_name = user_name.replace("[", "");
}
if(user_name.contains("]")){
user_name = user_name.replace("]", "");
}
users.add(user_name.trim())
}
Once that's done, following code works perfectly to remove multiple users:
Code:
private static final String DELETE_USER_NAME=
"DELETE FROM User x WHERE x.name in (:usernames) and x.id = userId";
@Override
public boolean deleteUserName(List<String> users, Integer userID) {
if (username!= null && !username.isEmpty()) {
Number result = em.createQuery(DELETE_USER_NAME)
.setParameter("usernames",users)
.setParameter("id", userID)
.executeUpdate();
return ((result.intValue() == 1) ? true : false);
}
else
return false;
}
thanks for all the support.