Hibernate / MyBatis Interview questions
What are the supported statement types in MyBatis?
MyBatis provides four core XML elements (and their annotation equivalents) corresponding to the standard SQL data manipulation operations, each with slightly different default behaviors around what they return.
| Element / Annotation | SQL Operation | Typical Return |
| <select> / @Select | SELECT | A single object, a list, or a map, per the method's return type |
| <insert> / @Insert | INSERT | Number of affected rows; can also return a generated key |
| <update> / @Update | UPDATE | Number of affected rows |
| <delete> / @Delete | DELETE | Number of affected rows |
Insert statements have a notable extra capability: using useGeneratedKeys and keyProperty attributes, MyBatis can retrieve an auto-generated primary key value from the database after an insert and automatically set it back onto the corresponding property of the inserted Java object, which is commonly used so the caller has the new row's ID immediately available without a separate follow-up query.
More Related questions...