简体   繁体   中英

MyBatis select statement WITHOUT a resultMap

I'm trying to avoid using resultMap's in MyBatis (or preferably without XML altogether).

I have the following working:

     <select id="getAllSales" resultType="Sales">
            SELECT TOP 100
                ID as "id",
                PLANE as "plane",
                PLANE_TYPE as "plane_type"
        FROM SALES
     </select>

This maps to a domain object (POJO) without issue. However, if I have a child domain object, there doesn't seem to be any info out there how to make this work. For example:

<select id="getAllSales" resultType="Sales">
                SELECT TOP 100
                    ID as "id",
                    PLANE as "plane.type",
                    PLANE_TYPE as "plane.type.serial_num"
            FROM SALES
 </select>

This will not map with a resultMap="Sales" attribute (Sales object is the parent object and contains the "Plane" type or, more specifically a List type.

Any suggestion or ideas on how to get away from using a resultMap within the XML file?

Even more desirable, would be to go away from XML files completely and use @ annotations in the interface.

Thank you.

Mybatis cannot guess an object property is a complex type if it is not "told" the relation is an association. It can be done when defining the resultMap in XML.

Concerning annotations, according to API documentation about @One :

join mapping is not supported via the Annotations API. This is due to the limitation in Java Annotations that does not allow for circular references

Absence of join is SQL query is irrelevant here, but this is the same scenario.

Annotations would be an option if you considered using nested select (why not with lazy loading). But you scheme does not seem to require/allow it.

Eventually, I guess XML is the only way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM