1

Hibernate has a dirty-checking mechanism which can auto-detect changes and generate appropriate UPDATE queries.

Is there any similar thing that exists for MyBatis?

I know there isn't any one-to-one mapping between a Java-Entity and DB-table in MyBatis, but we do specify resultMaps. Is there any way in MyBatis that can intelligently calculate the diffs for an object and trigger appropriate UPDATE queries, without the developer explicitly writing them?

Lavish Kothari
  • 1,580
  • 14
  • 23

1 Answers1

1

No, mybatis does not support this. There is no query generation in mybatis. mybatis is a tool that helps you execute SQL easier and map results from JDBC to objects easier.

As you noticed mybatis does not map tables to entities but rather result sets to objects.

Mybatis does not maintain any kind of persistent context so it does not track any changes to objects it returns (these objects are not even required to have any identifiers or be of user defined type).

You may also want to check this question and its answers that go into more details about the difference and give more insights about the reasons why mybatis does not support this.

Roman Konoval
  • 12,545
  • 2
  • 32
  • 46