Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7713281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:50:11+00:00 2026-06-01T01:50:11+00:00

I have a select defined in mapper.xml file: <mapper namespace=foo> <select id=selectWithRoles parameterType=String resultMap=personWithRoles>

  • 0

I have a select defined in mapper.xml file:

<mapper namespace="foo">

  <select id="selectWithRoles" parameterType="String" resultMap="personWithRoles">
    select * 
    from 
    PERSON P
    left outer join PERSON_ROLE R on P.ID = R.PERSON_ID
    where P.ID = #{id}
  </select>  

  <resultMap id="personWithRoles" type="Person">
    <id property="id" column="ID" />
    <collection property="roles" ofType="Role">
      <id property="personId" column="PERSON_ID"/>
      <result property="name" column="NAME"/>
    </collection>
  </resultMap>

</mapper>

and I want to expose this select via DAO Interface through annotation(s) without copying select statements into DAO. Following works fine:

@Select("select * from PERSON P left outer join PERSON_ROLE R on P.ID = R.PERSON_ID where P.ID = #{id}")
@ResultMap("personWithRoles")
public Person loadByIdWithRoles(String id);

But I don’t like copying SQL into annotation (could be pretty long) want something like this:

@Select("selectWithRoles")
public Person loadByIdWithRoles(String id);

where “selectWithRoles” is id of select defined in XML. Is it possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T01:50:13+00:00Added an answer on June 1, 2026 at 1:50 am

    Found an answer. In case anybody would need it: apparently as long as the namespace in the XML file matches the fully qualifies name of interface AND the method name matches the id in XML, then MyBatis will magically make it work with no annotation.

    <mapper namespace="foo">
    
      <select id="selectWithRoles" parameterType="String" resultMap="personWithRoles">
        select * 
        from 
        PERSON P
        left outer join PERSON_ROLE R on P.ID = R.PERSON_ID
        where P.ID = #{id}
      </select>  
    
      <resultMap id="personWithRoles" type="Person">
        <id property="id" column="ID" />
        <collection property="roles" ofType="Role">
          <id property="personId" column="PERSON_ID"/>
          <result property="name" column="NAME"/>
        </collection>
      </resultMap>
    
    </mapper>
    

    Note that package name matches with namespace in XML and method name matches select id:

    package foo;
    public Person public Person selectWithRoles(String id);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have SELECT name FROM table which gives me something like foo
I have defined the following query: select count((select * from producers)) from producers; Assuming
Background: I have this with rollup query defined in MySQL: SELECT case TRIM(company) when
suppose I have SELECT * FROM table t GROUP BY j HAVING condition_one OR
Right now, I have SELECT gp_id FROM gp.keywords WHERE keyword_id = 15 AND (SELECT
I have a select box defined as shown below. I want to print out
I have a series of select boxes whose content is dynamically defined, the options
I have a view that's currently defined as CREATE VIEW riders AS select ridelog
I have a map of pre-defined colors and a given color to select one
I have defined the following select list: <%= this.Select(Scope) .Options(Scopes.AllValues) // static property to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.