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
声明式事物
你的主键生成方式是什么啊?
用户登录
还没有账号?立即注册
用户注册
投稿取消
文章分类: |
|
还能输入300字
上传中....