java - 一起使用 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.
请帮帮我。
解决方案
推荐阅读
- java - EqualsAndHashCode.Exclude 无法解析为类型
- azure - 无法在 azure 中调试应用服务:MSVSMON 似乎没有运行
- c - 动态定义和分配指针
- r - 截止值以上的累积曲线下面积
- python - 使用 pandas 单独组合 excel 工作表
- javascript - 为什么拆分未定义?
- javascript - javascript 为对象中的所有属性设置
- camera - Android Things - IMX7d 上的前置摄像头
- kendo-ui-vue - kendo-grid-column 可过滤道具上的 Kendo vue 包装器错误
- jasmine - Jasmine spyOn 迁移到 Webpack4 后失败