Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加商品属性存在原子型问题 #491

Open
stulwd opened this issue Jun 28, 2021 · 1 comment
Open

添加商品属性存在原子型问题 #491

stulwd opened this issue Jun 28, 2021 · 1 comment

Comments

@stulwd
Copy link

stulwd commented Jun 28, 2021

背景:添加产品属性对于属性分类表有两次数据库操作,第一次获取对应的分类记录,第二次把属性数量累加了1更新数据库。
问题:如果要是存在并发的情况,比如两个线程同时读取完了分类记录,获得的属性数量是一致的,那么两个线程同时加1,然后分别更新,就会导致实际只加了1而不是2。

@VeniVeci
Copy link

VeniVeci commented Dec 3, 2023

image
请问方便贴一下代码吗,没有找到“添加产品属性对于属性分类表有两次数据库操作” 这段代码。
代码中使用productAttributeValueDao插入getProductAttributeValueList时,id是自增的,应该不会有线程安全的问题。

        //添加商品参数,添加自定义商品规格
        relateAndInsertList(productAttributeValueDao, productParam.getProductAttributeValueList(), productId);
        
<mapper namespace="com.macro.mall.dao.PmsProductAttributeValueDao">
    <insert id="insertList">
        insert into pms_product_attribute_value (product_id,product_attribute_id,value) values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.productId,jdbcType=BIGINT},
            #{item.productAttributeId,jdbcType=BIGINT},
            #{item.value,jdbcType=VARCHAR})
        </foreach>
    </insert>
</mapper>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants