Hibernate vs. iBatis ( updated )

Hibernate and iBatis are both Database Persistence Frameworks.

Here’s the difference of both, and which to choose for appropriate usage.

Hibernate – Hibernate is seen as larger and has more functionality, and seems to be more advanced in Cache. It offers a close to Java oriented coding where there is less bother on SQL. Downside of large frameworks is the learning curve to learn something new aside from the SQL.

Hibernate workflow:

1.) Database connectivity is already encapsulated, just edit a config file and add the Database location/URL , username and password.

2.) There is a need to create an xml file and POJO ( with getters and setters ) that maps to a database table. Only one xml file and one POJO for each corresponding table.

3.) Create a Java Code, then use the hibernate methods to access the database. In a hibernate funtion, you may use SQL , HQL or none, as it depends on the method used.

Example of HQL java code:
> http://examples.javacodegeeks.com/enterprise-java/hibernate/hibernate-query-language-example/
> http://www.mkyong.com/hibernate/hibernate-query-examples-hql/

MyBatis – ( previously called iBatis ) is much more simplified and lightweight compared to Hibernate. Also best to use if there is an already existing live ( complex ) database, since it has the ability to map it easily because of its simple approach. iBatis still uses SQL and does not encapsulate it unlike Hibernate.

MyBatis workflow:

1.) Database connectivity is already encapsulated, just edit a config file and add the Database location/URL , username and password, which is quite similar to Hibernate.

2.) Create a DTO which is a POJO that similary corresponds to a database table or a structured dataset.

3.) All SQL commands and queries are written in the xml mapper file. Then each entry of a SQL set command is mapped to the DTO java file. There can be multiple mapper files and DTO files, as needed.

4.) To use the SQL commands, use the DTO java file and use the methods with the corresponding parameters as described in the xml mapper file.

Example of Mapper files.
> https://mybatis.github.io/mybatis-3/sqlmap-xml.html
> http://examples.javacodegeeks.com/enterprise-java/mybatis/how-create-mybatis-mapper/

Summary:

For a more Java and Object Oriented approach, Hibernate provides this. If comfortable to use SQL, and less on Java coding, iBatis can do it.

See more from this site:

http://www.tutorialspoint.com/ibatis/ibatis_vs_hibernate.htm

Advertisements

One thought on “Hibernate vs. iBatis ( updated )

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s