mybatis-插入交易 [英] mybatis - insert transaction
本文介绍了mybatis-插入交易的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
用于插入的mybatis映射器代码:
mybatis mapper code for insert:
<insert id="insert" parameterType="Shop" useGeneratedKeys="true">
insert into shop(email, pswd, nickname, mobile, city, create_date, status) values (#{email}, #{pswd}, #{nickname}, #{mobile}, #{city}, #{createDate}, #{status})
<selectKey keyProperty="id" order="AFTER" resultType="long">
select currval('shop_id_seq')
</selectKey>
</insert>
数据库是PostgreSQL 9.3.
The database is postgresql 9.3.
我的怀疑是:没有显式事务,当我使用select currval('shop_id_seq')
从序列中检索ID时,如果其他线程也在执行插入操作,是否有可能得到错误的值?
My doubt is: without explicity transaction, when I retrieve the id from sequence with select currval('shop_id_seq')
, is it possible to get the wrong value if other threads are also doing insert?
我认为不会,因为currval()函数在当前会话而不是全局会话的上下文中运行,但是我不确定.
I thought it won't, because currval() function runs in context of current session, not global session, but I am not that sure.
推荐答案
查看全文