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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:11:13+00:00 2026-05-23T13:11:13+00:00

(Using MyBatis v3.0.4.) I have a problem that I do not know how to

  • 0

(Using MyBatis v3.0.4.)
I have a problem that I do not know how to solve. My object model is:

Location.java


public class Location {
    // ... other content
    private List addresses; 
    // ... other content
}

Address.java


public class Address { 
    public enum Type { POSTAL, POBOX, INPUT, CLEANSED } 
    private Type type; 
    private String line1; 
    // ... other content
}

My SQL is:


SELECT 
    // ... other content 
    postal_address_line_1, 
    postal_address_line_2, 
    postal_address_city, 
    cleansed_address_line_1, 
    cleansed_address_line_2, 
    cleansed_address_city, 
    // ... other content

How would I construct a resultMap that would plug the appropriate
columns into an address instance of the correct type and added to the
same list in Location.java? I would like to avoid having to add
another instance variable to Location.java just to hold a different
type of address.

  • 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-05-23T13:11:14+00:00Added an answer on May 23, 2026 at 1:11 pm

    Along the lines of Andy Pryor’s suggestion, I was able to solve the problem by updating my SQL statement to something like the following:

    SELECT 
    // ... other content 
    'POSTAL' as Postal_Address_Type,
    postal_address_line_1, 
    postal_address_line_2, 
    postal_address_city,
    'CLEANSED' as Cleansed_Address_Type,
    cleansed_address_line_1, 
    cleansed_address_line_2, 
    cleansed_address_city, 
    // ... other content
    

    Then update my resultMap to the following:

    <resultMap ...>
        //... other content
        <association property="postalAddress" javaType="com.x.y.z.Address">
            <result property="type" column="Postal_Address_Type"/>
            <result property="line1" column="Address_Part_1_Name"/>
            <result property="line2" column="Address_Part_2_Name"/>
            //...other content
        </association>
        <association property="cleansedAddress" javaType="com.x.y.z.Address">
            <result property="type" column="Cleansed_Address_Type"/>
            <result property="line1" column="Address_Part_1_Name"/>
            <result property="line2" column="Address_Part_2_Name"/>
            //...other content
        </association>
    </resultMap>
    

    Finally, within my Address class I am able to have setType(Type) and the inbuilt enumerated type handler does the magic. Within the Location class I can just have one list of instances of Address and the various setXXXAddress() methods can add to this list appropriately.

    It is unfortunate that I cannot plug the columns into some sort of factory class but putting hard-coded types into the SQL statement isn’t too dirty, in my opinion. The disadvantage is that I have introduced coupling between the domain model’s Address.Type values and the SQL statement but this is kind of already there given that the resultMap SQL XML needs to hold the names of instance variables in the Address class anyway.

    • 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 swing app and I am using mybatis: public class MyAppCView
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I am using MyBatis 3.0.3 and have problem: some columns in database have names
Using C#, I need a class called User that has a username, password, active
using namespace boost; class A {}; class B : public A {}; class X
I have been trying to create a Spring project that uses MyBatis for the
Using CRM 4, I have an entity form that contains a tab with an
We're using MyBatis (3.0.5) as our or-mapping tool (and I don't have any say-so
Using Java, assuming v1.6. I have a collection where the unique index is a
Using Browserlab, it appears that the background image is not centred in Firefox7 for

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.