Tag Archives: @Insert

Mybatis Insert Using XML or Annotation & Return Primary ID

This is a short post on how to use MyBatis to insert an object using XML <insert> or annotation @Insert and return the value of the primary id.

mybatis

The complete code on GitHub is using Spring & H2 embedded database to provide ready to run example.

>mvn exec:java

Objectives:

  • How to use <insert..> & @Insert to insert an object?
  • How to get primary Id of the inserted object?

Continue reading

Mybatis + Spring (XML | Annotation) Mapper

Here we will see what we need to do to connect to a relational database “MySql, Oracle, H2..etc” using myBatis with Spring framework & how to implement mappers using xml or annotation such as @Select, @Insert,….etc. For the sake of simplicity I have used H2 embedded database so you can run the sample code. However, you can use this sample code to run with MySql or any other relational database.

Source Code @ github

Note: If you have Maven you can run this sample code directly using 
../spring-mybatis>mvn exec:java

mybatis-spring

Objectives:

  • How to use MyBatis with Spring framework?
  • How to implement mapper using xml or annotation @Select, @Insert…?

Continue reading