Hibernate 事务未正常启动????
2009-06-17 19:18
183 查看
Exception in thread "main" org.hibernate.TransactionException: Transaction not successfully started
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:100)
at app.Test.count(Test.java:77)
at app.Test.main(Test.java:46)
源码如下:
// 统计每种类型产品的数量,包括子类型下面的类型。直到根类型是null
@SuppressWarnings("unchecked")
static void count()
{
Session session = sessionFactory.openSession();
Transaction tran = session.beginTransaction();
Query query = session.createQuery(" from Product");
List<Product> list = query.list();
for (Product p : list)
{
// 输出测试
System.out.println("name:" + p.getName());
ProductType type = p.getType();
// 输出测试
System.out.println("name:" + type.getName());
type.setCount(type.getCount() + 1);
// 更新类型的数量
session.update(type);
ProductType parent = type.getParents();
while (parent != null)
{
// 输出测试
System.out.println("name:" + parent.getName());
parent.setCount(parent.getCount() + 1);
// 更新类型的数量
session.update(type);
parent = parent.getParents();
}
tran.commit();
}
session.close();
}
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:100)
at app.Test.count(Test.java:77)
at app.Test.main(Test.java:46)
源码如下:
// 统计每种类型产品的数量,包括子类型下面的类型。直到根类型是null
@SuppressWarnings("unchecked")
static void count()
{
Session session = sessionFactory.openSession();
Transaction tran = session.beginTransaction();
Query query = session.createQuery(" from Product");
List<Product> list = query.list();
for (Product p : list)
{
// 输出测试
System.out.println("name:" + p.getName());
ProductType type = p.getType();
// 输出测试
System.out.println("name:" + type.getName());
type.setCount(type.getCount() + 1);
// 更新类型的数量
session.update(type);
ProductType parent = type.getParents();
while (parent != null)
{
// 输出测试
System.out.println("name:" + parent.getName());
parent.setCount(parent.getCount() + 1);
// 更新类型的数量
session.update(type);
parent = parent.getParents();
}
tran.commit();
}
session.close();
}
相关文章推荐
- Hibernate 事务未正常启动????
- 今天总结:关于hibernate事务乐观锁和elipse启动tomcat报内存不足的最终解决方案
- 程序在tomcat运行正常,但部署到websphere会启动失败(org.hibernate.InvalidMappingException: Could not parse mapping doc)
- hibernate的增加、修改方法不生效,查询正常【事务没有拦截到导致的】
- 【小技巧】firefox无法正常启动的解决方案
- WIn7修复开机引导解决无法正常启动
- 关于nginx不能随服务器启动而正常启动的修复脚本
- Spring Hibernate事务配置总结
- MAMP无法正常启动,错误提示The built-in Apache is active
- 20160515-hibernate--事务
- 整合spring和hibernate框架中事务的声明
- 【hibernate框架】事务并发处理
- 使用hibernate的事务讲解
- 解决windows 2003+Sql2000中OLEDB分布式事务无法启动的解决方案
- Spring管理Hibernate事务
- ADO事务处理方式运行正常
- hibernate 之session 事务管理
- hibernate的事务管理
- 应用程序无法正常启动0Xc000007b opencv+vs2010 编译通过,运行出错
- sqlserver提示“在流水模式下,事务无法启动”的解决办法