Tag Archives: H2

MyBatis + Spring + Junit (The Missing Part)

We have seen in Mybatis + Spring (XML | Annotation) Mapper how to write a simple mybatis-spring app and what is actually needed to get it up and running. Here I will extend that sample code to cover more stuff that you may face in a real “coding”. We will see how to make a single select that will fetch the one and the many of a “one-to-many” relationship, who to use mybatis config file with spring (if you need it), how to test mybatis-spring code using junit and things you need to watch out!

H2 embedded database has been used to make this example easy to run. But you still can use it with other databases e.g. “MySql, Oracle,….”



  • How to use make a single select that will fetch all one to many records?
  • How to reference mybatis config file in spring xml config file?
  • How to test using junit?

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



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

Continue reading

Relational “H2″ vs. Graph “Neo4j”

We will test the performance of Neo4j graph database against a relational database. I have selected H2 to represent the relational database community because it is light and assumed to be very fast. So, simply we will build a data model that represents relations among a set of people in both databases. Then we will test their performance by trying to ask “query” some questions.

The Story:

We have a set of 1000 persons each of them knows exactly 50 persons from the same set. We will build this data model in both databases using the below Java application. The relation between each person to his 50 friends will be randomly generated but it will be same on both databases.


  • Test the performance of Neo4j against relational database “H2″.

Continue reading