2011-02-15

MyBatis component in Apache Camel 2.7

I have been a fan of the iBatis SQL mapper for a long time. And been using it in it's early days, when Clinton Begin started the project. I even think there was (or used to be) a few patches in the iBatis source code from me, from its early days. It's still running out in Shanghai in the grand custom clearance system I helped develop back in 2003.

As you may know the project team behind iBatis moved to a new home outside Apache and named the new project MyBatis. I have wanted to create a camel-mybatis component for some time. Now that the Camel in Action book is done, I have more spare time to work on some fun stuff.

So in Camel 2.7 we have added a new camel-mybatis component which works similar to the existing camel-ibatis component. This should allow you to more easily migrate off the iBatis to the MyBatis.

You may ask why I am in favor of iBatis/MyBatis. Well one of the reason its simple and it does exactly what it's told to do. And it gives you, the end user, full power. I have seen to many projects picking an ORM such as Hibernate / JPA for any database access, and then crumple into misery.

Especially in integration scenarios where you have use-cases to maintain data in an existing scheme, then using plain SQL (with Spring SimpleJdbcTemplate) is a good solution. Even a stored procedure may remedy some use-cases where a complex query has to be executed fast and being optimized on the target database. If there is a bit more database work in need then using MyBatis is a great SQL mapper which still gives you the full power of the SQL, but makes it dead easy to map ResultSet to/from Java objects.

At Javalobby there was a discussion about people using plain JDBC. If you take a look at some of the comments, then not everybody is in favor of ORMs. I strongly suggest to think twice when using an ORM.

No comments: