简体   繁体   English

MyBatis 是否有类似 Hibernate 的“脏检查机制”?

[英]Is there an “dirty checking mechanism” for MyBatis similar to that in Hibernate?

Hibernate has a dirty-checking mechanism which can auto-detect changes and generate appropriate UPDATE queries. Hibernate 具有脏检查机制,可以自动检测更改并生成适当的UPDATE查询。

Is there any similar thing that exists for MyBatis ? MyBatis是否存在类似的东西?

I know there isn't any one-to-one mapping between a Java-Entity and DB-table in MyBatis, but we do specify resultMap s.我知道 MyBatis 中的 Java-Entity 和 DB-table 之间没有任何一对一的映射,但我们确实指定了resultMap 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? MyBatis 中是否有任何方法可以智能地计算 object 的差异并触发适当的UPDATE查询,而无需开发人员明确编写它们?

No, mybatis does not support this.不,mybatis 不支持这个。 There is no query generation in mybatis. mybatis 中没有查询生成。 mybatis is a tool that helps you execute SQL easier and map results from JDBC to objects easier. mybatis 是一个工具,可以帮助您更轻松地执行 SQL 并将 map 结果从 JDBC 到对象更容易。

As you noticed mybatis does not map tables to entities but rather result sets to objects.正如您所注意到的,mybatis 不会将 map 表转换为实体,而是将结果集转换为对象。

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). Mybatis 不维护任何类型的持久化上下文,因此它不会跟踪它返回的对象的任何更改(这些对象甚至不需要具有任何标识符或是用户定义的类型)。

You may also want to checkthis 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.您可能还想查看此问题及其 go 的答案,以了解有关差异的更多详细信息,并提供有关 mybatis 不支持此功能的原因的更多见解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM