Transaction tran=session.begionTransaction();
................
................
................
................
tran.commit();
声明事务,
最后在save()完成之后,commit();
可能是懒加载的问题。
你去hibernate反向工程生成的那个类的对应的映射文件里面看看
把它改成lazy=”false”.
setautocommit 默认是true 说明save方法是自动提交的
还有这个方法是java.sql.connection借口提供的 不是hibernate的
方法说明如下:
void setautocommit(boolean autocommit)
throws sqlexception将此连接的自动提交模式设置为给定状态。如果连接处于自动提交模式下,则它的所有 sql 语句将被执行并作为单个事务提交。否则,它的 sql 语句将聚集到事务中,直到调用 commit 方法或 rollback 方法为止。默认情况下,新连接处于自动提交模式。
提交发生在语句完成时。语句完成的时间取决于 sql 语句的类型:
对于 dml 语句(比如 insert、update 或 delete)和 ddl 语句,语句在执行完毕时完成。
对于 select 语句,语句在关联结果集关闭时完成。
对于 callablestatement 对象或者返回多个结果的语句,语句在所有关联结果集关闭并且已获得所有更新计数和输出参数时完成。
注:如果在事务和自动提交模式更改期间调用此方法,则提交该事务。如果调用 setautocommit 而自动提交模式未更改,则该调用无操作(no-op)。
参数:
autocommit - 为 true 表示启用自动提交模式;为 false 表示禁用自动提交模式
抛出:
sqlexception - 如果发生数据库访问错误,在参与分布式事务的同时调用 setautocommit(true),或者在关闭的连接上调用此方法
还有save方法是在org.hibernate.session这个接口里
save
serializable save(object object)
throws hibernateexceptionpersist the given transient instance, first assigning a generated identifier. (or using the current value of the identifier property if the assigned generator is used.) this operation cascades to associated instances if the association is mapped with cascade="save-update".
parameters:
object - a transient instance of a persistent class
returns:
the generated identifier
throws:
hibernateexception
声明式事物
你的主键生成方式是什么啊?
热门文章更多>>
标签更多>>
专题更多>>
最新文章更多>>
- iOS 14/iPadOS 14开发者预览版Beta8升级方法及更新内容
- 质因数分解板子
- 简介iOS开发中应用SQLite的模糊查询和常用函数
- 约瑟夫优化
- iOS/iPadOS 14.2Beta 1怎么升级?iOS/iPadOS 14.2开发者预览版Beta 1升级方法
- iOS13.7还能降级吗 iOS13.6.1已关闭验证
- iOS14提醒事项App有哪些改动 iOS14提醒事项功能介绍
- iOS14如何修改小组件 小组件添加和删除方法
- 苹果 iOS 14 Beta 7怎么样 苹果iOS14开发者预览版Beta7更新内容
- iOS/iPadOS 14 Beta 7值得升级吗?iOS/iPadOS 14 Beta 7更新介绍
IS--7