Eshu Yadav
Eshu Yadav

Reputation: 71

why mybatis update and delete are not working?

I am developing a microservice using myBatis but UPDATE and DELETE statements are not working in it. Even simple update statements are not executing whenever I execute it just stuck and no response

<update id = "update" parameterType="map">
        UPDATE TESTDB 
             SET
                <foreach item = "entry" index = "key" separator = "," collection = "SET">
                     ${key} = #{entry}
                </foreach>

            WHERE
                <foreach item = "entry" index = "key" separator = "AND" collection = "WHERE">
                     ${key} = #{entry}
                </foreach>

    </update>

calling function

session.update("test.update",map);

map contains SET and WHERE keys and values as per json request given below

As I am using PUT method so my json request which I am putting in maps such as SET and WHERE.

{
"data":
[   
    {
        "set":
        [
            {
                "ID":"2",
                "NAME":"abc",
                "TYPE":"abc"
            }
        ],
        "where":
        [
          {

                 "NAME":"a",
                 "ID":"1"
          }
        ]
    }
]

}

I am getting correct query in logs but when I execute it through POSTMAN I am getting these, It shows that it's sending and loading and doesn't execute just stuck that it's sending but no response.

This issue is with only delete and update query rest are working fine.

POSTMAN REQUEST SENDING

Upvotes: 2

Views: 1660

Answers (1)

Eshu Yadav
Eshu Yadav

Reputation: 71

Thank you @Smile.

I got reason why it was failing. I have created a SqlSession and that session is being used by all operations and that session locks the row(s) which I am trying to update or delete.

Solution:-

  1. Make separate session for all operations.

  2. Check whether session is null or not make it null if it points to some other previous session and assign new session in it using sqlSessionFactory so that it won't locks the rows(s).

Upvotes: 1

Related Questions