用户登录
用户注册

分享至

hibernate save 事务

  • 作者: 各位看官我是狗
  • 来源: 51数据库
  • 2020-10-15

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


软件
前端设计
程序设计
Java相关