您的位置:首页 > 其它

Hibernate 事务未正常启动????

2009-06-17 19:18 281 查看
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();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: