tags:

views:

147

answers:

1

I am specifically interested in moving away from XML-based mapper configuration to using pure Java annotations where the SQL statements often take or return complex data structures.

Also, it wasn't clear in the samples I saw, how the configuration file was adapted when moving away from XML-based mappers to annotation-based Mapper interfaces.

A: 

Nomenclature: The entire core development team has moved to Google Code, and are maintaining the project under a new name, MyBatis.

Answer:

  1. I'm pretty sure there are no decent tutorials for annotations beyond the user guide on the project site.

  2. In your main configuration file (e.g. mybatis-3-config.xml), simply do not include a "mappers" element.

Advice: I would actually recommend sticking with the XML, because many non-trivial mappings are actually impossible to accomplish with Java annotations. On page 57 of the user guide (http://mybatis.googlecode.com/svn/trunk/doc/en/MyBatis-3-User-Guide.pdf), it says:

Despite a lot of time spent in investigation, design and trials, the most powerful MyBatis mappings simply cannot be built with Annotations – without getting ridiculous that is. C# Attributes (for example) do not suffer from these limitations, and thus MyBatis.NET will enjoy a much richer alternative to XML.

What specifically would you like help figuring out how to do with annotations?