0

Here is my code in dao layer..can anyone please help me to delete multiple records from database in the table mapped to SabbModelPrd using the condition equal to ("clientid", strClientId) which is not the primary key . Thanks in advance...

 public boolean deleteAllServices(String strClientId){
    boolean flag = false;
    try {
        Session session  = sessionFactory.getCurrentSession();
        SabbModelPrd sabbModelPrd = (SabbModelPrd) session.get(SabbModelPrd.class, strClientId);
        if (!StringUtils.isEmpty(sabbModelPrd)) {
            session.delete(sabbModelPrd);
            flag = true;
        }
    } catch (Exception e) {

    }
    return flag;
}

here its checking strClientId with the primary key product_id

0

1 Answer 1

0
 public boolean deleteAllServices(String strClientId){
    boolean flag = false;
    try {
        Session session  = sessionFactory.getCurrentSession();
        SabbModelPrd sabbModelPrd = (SabbModelPrd) session.createQuery("delete FROM SabbModelPrd where strClientId like'"+strClientId+"'");
flag= true;
    } catch (Exception e) {
return flag;
    }
    return flag;
}

I hope its gonna help you

Sign up to request clarification or add additional context in comments.

3 Comments

While this code may answer the question, it would be better to explain how it solves the problem and why to use it. Code-only answers are not useful in the long run.
the get method gives you a list of the class you give as a param (SabbModelPrd.class in your case) and insteadof getting a list of object and remove from this list it better to use sql and remove directly from database
Here on Stackoverflow you can always edit your posts to improve them. And punctuation matters.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.