Mybatis Annotations in Complex Applications

2019-07-09 05:53发布

问题:

I am currently working on a project that uses MyBatis annotations in mapper interfaces as I prefer this to XML files but have been running into issues mapping assocations.

i.e. loading a collection for a one to many assocaition that uses a join table.

I know that annotations do not support some association mappings. Is it still possible to use MyBatis with mapper interfaces in Java in any moderately complex application without resorting to xml mapping files, considering the limitations?

Is there any issues combining mapper interfaces with xml mapping files.

回答1:

The user guide admits that the annotation format gets unwieldy for complex queries. But, you can combine annotation and XML query definitions, and the requirement ends up being that there cannot be more than one definition of with the same name, no matter how it's defined.

I'm currently working through MyBatis Koans -- which I'm finding quite useful. The 8th exercise includes a mapper interface with annotations for the delete methods, and a mapper XML file for updates, inserts and selects. It worked for me with no issues, once I had the exercise completed.