MyBatis Multiple Query Parameters - property of an Object Type
MyBatis Multiple Parameters
I have been using ibatis (now mybatis) for quite sometime now. It is really quite a powerful ORM. It has come a long way and there are a lot if improvements from the xml configuration based version to the new annotations. Here are some things that i like the most:
1. the SQL builder class (SQL Builder Class)
I was looking at other ways to use SQL in my projects like JOOQ (JOOQ DSL) because it offers generating SQL via typesafe way using DSL. I am so glad that myBatis has this typesafe way of creating SQL too.
2. the typeHandler - you never know when you are going to need one specially in java type to jdbc type conversions. For example time formats (joda-time)
3. the provider annotations (InsertProvider, SelectProvider, etc..) - gives you a flexible way of generating your SQL statements dynamically. Recently used a 'MERGE' statement in Oracle. I wonder if i could have used that with JOOQ ?
4. the SQL statement parameters - Did you know that you can use "." (dot) to get a nested property ? Example below:
@Select("SELECT * FROM EMPLOYEE WHERE NAME = #{bean.property}
AND ID =#{id}")
public EmployeeVO doSelectEmployee(@Param("bean") Bean bean, @Param("id") String id) throws Exception;
myBatis will recursively look for the "property" in bean and substitute the value properly.
Comments
"I am so glad that myBatis has this typesafe way of creating SQL too."
I wonder how far you'll get with that SQL Builder Class :-)
"the typeHandler [...]"
You can use any custom data type (including joda-time, of course) with jOOQ as well:
http://www.jooq.org/doc/3.2/manual/code-generation/custom-data-types/
"Recently used a 'MERGE' statement in Oracle. I wonder if i could have used that with JOOQ ?"
Of course!
http://www.jooq.org/doc/3.2/manual/sql-building/sql-statements/merge-statement/
"the SQL statement parameters"
That's really a nice MyBatis feature. I'll have to remember implementing that in jOOQ as well!
Thanks again for the comparison,
Lukas