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.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
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货