首页 > 解决方案 > 一起使用 openSession() 和 getCurrentSession()

问题描述

我是休眠的新手,下面是我的用例。

@EnableTransactionManagement
class A{

   @Autowired
   SessionFactory sessionFactory;

   @Transactional
   public void getProducts(String id) {
      List<Products> products = sessionFactory.openSession().fetch(id);
      getProductsDetials(products);
   }

   @Transactional
   public List<String> getProductsDetails(List<Products> products) {
      List<String> productName = new ArrayList();
      for(Products product : products) {
         roductName.add(sessionFactory.getCurrentSession().fetch(product.getId()));
      }
   }
}

尝试从数据库中获取产品名称时出现以下异常getProductsDetails

or.hibernate.exception.GenericJDBCException : could not prepare statement.

请帮帮我。

标签: javaspringhibernate

解决方案


推荐阅读