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

  • Home
  • SEARCH
  • 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 6645597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:18:26+00:00 2026-05-26T00:18:26+00:00

Maybe I am missing something obvious, but I cannot get a simple mapped insert

  • 0

Maybe I am missing something obvious, but I cannot get a simple mapped insert statement executing successfully.

Using the following interface

public interface CustomItemMapper 
{
    Integer insert(CustomItem item, @Param("extra") String someparam);
}

and the following XML mapping

  <insert id="insert" useGeneratedKeys="false" parameterType="map" keyProperty="id">
    insert into CustomItem (id, column2, column3, column4, column5, column6)
        values (#{id}, #{field2}, #{field3}, #{field4}, #{field5}, #{extra})
  </insert>

and this code

SqlSessionFactory sqlSessionFactory = (SqlSessionFactory) servletContext.getAttribute("SqlSessionFactory");
SqlSession session = sqlSessionFactory.openSession();
try 
{ 
    CustomItemMapper mapper = session.getMapper(CustomItemMapper.class); 
    mapper.update(item);
    session.commit();
} 
finally 
{ 
    session.close(); 
} 

I get the following debug output:

Checked out connection 368716606 from pool.
ooo Connection Opened
==>  Executing: insert into CustomItem (id, column2, column3, column4, column5, column6) values (?, ?, ?, ?, ?, ?) 
==> Parameters: null, null, null, null, null, actual_value_of_extra(String)
xxx Connection Closed
Returned connection 368716606 to pool.

followed by the SQL exception (cannot enter null into the id column).

So the only value that was passed in properly is the extra supplied string. I have verified that the field names are correct and object is not null at this point and the fields are populated properly.

I also tried using parameterType="CustomItem" instead of parameterType="map" but the result did not change.

I would appreciate if someone could let me know what I am missing here.

Thanks in advance.

PS: I get into the same problem with insert statements, as well.

  • 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-26T00:18:27+00:00Added an answer on May 26, 2026 at 12:18 am

    You need to specify the name of the other parameter in your mapper method. I’m assuming CustomItem is a Java bean, with get methods for field1 etc. As already mentioned, change your parameter type, so that it is not Map.

    From mybatis documentation,

    You can pass multiple parameters to a mapper method. If you do, they
    will be named by their position in the parameter list by default, for
    example: #{1}, #{2} etc. If you wish to change the name of the
    parameters (multiple only), then you can use the @Param(“paramName”)
    annotation on the parameter.

    So, change your Mapper,

    public interface CustomItemMapper 
    {
        Integer insert(@Param("item")CustomItem item, @Param("extra") String someparam);
    }
    

    and change your xml to,

     <insert id="insert" useGeneratedKeys="false" parameterType="map" keyProperty="id">
        insert into CustomItem (id, column2, column3, column4, column5, column6)
            values (#{id}, #{item.field1}, #{item.field2}, #{item.field3}, #{item.field4}, #{extra})
      </insert>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Maybe I'm missing something obvious, but I how can I view the expression tree
Ok, maybe I'm missing something here but I'm looking at various PHP hosting options
I may be missing something obvious, but how do you calculate 'powers' in SAS?
I'm writing my first expect script, so I may be missing something obvious, but
Maybe there's something obvious that I'm missing or maybe not. Suppose I have a
I'm may be missing something but I can't find the Delphi 2007 WSDL Importer
Maybe I'm missing it somewhere in the PHP manual, but what exactly is the
Am I thinking about this incorrectly?? Or missing something completely obvious? I can best
I may be missing something obvious about this in the documentation for addKeyListener ,
I know this is probably really obvious, but I cannot figure out why I

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.