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 8564023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:06:11+00:00 2026-06-11T17:06:11+00:00

I have database which has two tables post: id post_name post_desc files: file_id file_name

  • 0

I have database which has two tables

  post: 
    id
    post_name
    post_desc        

  files:
    file_id
    file_name

  post_attachments
    post_id
    file_id

In my xml mapping I already have

  <select id="selectPosts" resultType="com.mycom.myproject.bean.postBean">  
     select id, post_name as postName from post
  </select>

So its a one to many realtionship. I want all the files attached to a post. I don’t understand how I can do the mapping in mybatis.

I have my PostBean like

public class PostBean extends Post {

 private List<FileAttachment> filesAttachment;
 //getter setter
}

I am using mybatis with spring and mysql as database
Please let me know if you need anything else.

–update–

I have modified my mapper.xml as

            <resultMap id="BaseResultMap" type="com.mycom.myproject.db.mybatis.model.post">
<!--
  WARNING - @mbggenerated
  This element is automatically generated by MyBatis Generator, do not modify.
  This element was generated on Tue Sep 11 10:14:08 BST 2012.
-->
<id column="id" jdbcType="BIGINT" property="id" />
<result column="post_name" jdbcType="VARCHAR" property="postName" />
<collection property="filesAttachment" ofType="com.mycom.myproject.db.mybatis.model.FileAttachment">
    <id property="fileId" column="file_id" />
    <id property="fileName" column="file_name" />
</collection>

— update2 —

Actually I have one mapping table also which I have created above so my query is like

   <select id="selectPosts" parameterType="string"  resultType="com.mycom.myproject.bean.postBean"> 
   select p.id, p.post_name, fa.file_id as fileId, fa.file_name as fileName from post p
left outer join files f on f.post_id = p.id join post_attachments pa on pa.file_id = f.post_id
where p.id = 371    

  </select>    
  • 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-11T17:06:12+00:00Added an answer on June 11, 2026 at 5:06 pm

    As shown in the manual, you have to write a more complex query and change the mapper.

    The request will be something like that :

    <select id="selectPosts" resultType="com.mycom.myproject.bean.postBean">  
        select id, post_name, file_id, file_name as postName from post left outer join files
    </select>
    

    And your result map :

    <resultMap id="detailedPostResultMap" type="Blog">
      <result property="id" column="id"/>
      <result property="name" column="post_name"/>
      <collection property=filesAttachment" ofType="FileAttachment">
         <id property="fileId" column="file_id"/>
         <result property="fileName" column="file_name"/>
      </collection>
    </resultMap>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database that has two tables, one of which contains a foreign
I have two tables in my database named...Requests and Balance tracker which has no
I have two tables in my database named...Requests and Balance tracker which has no
Suppose I have a database named MyDatabase which has two tables - MyTable1 and
My database has two tables, question and field. Questions may have many fields, and
I have two tables in my database which have a one-to-one relationship. I want
I have two tables in two databases. Database 1 which is named db1 which
I have a SQLITE database with two tables. Table A has an integer timestamp
I have a database, which has 5 tables, but I have problem. In the
I have a database which has a table recording when a vehicle was last

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.