0

The method shown below is not fetching data from db with the criteria strProductId. I'm getting the value of strProductId inside the method. Can anyone please help..Thanks in advance....

public List<ProductServices> getAllServices(String strProductId){
        Session session = sessionFactory.getCurrentSession();
        Criteria cr = session.createCriteria(ProductServices.class);
        cr.add(Restrictions.eq("productId", strProductId));
        return (List<ProductServices>) cr.list();
    }
2
  • you tryto get the value of strProductId inside the method and strProductId is here param, thast is strange. Commented Nov 19, 2015 at 7:35
  • yes i'm getting strProductId from service layer as parameter but is there any mistake while giving criteria Commented Nov 19, 2015 at 7:41

2 Answers 2

1

Method getAllServices must be in a transaction. Check it, please.

Updated

You must open a transaction, do a request and close a transaction. It can be done by Spring of course. See this example. UserManagerImpl has a @Transactional annotation on methods.

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

Comments

0

you can do some thing like this

Session session = factory.openSession();
Transaction tx = null;
try {
    tx = session.beginTransaction();
    Criteria cr = session.createCriteria(ProductServices.class);
    cr.add(Restrictions.eq("productId", strProductId));
    return (List<ProductServices>) cr.list();
      tx.commit();
     }
   catch (Exception e) {
      if (tx!=null) tx.rollback();
       e.printStackTrace(); 
  }finally {
  session.close();
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.