question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@Select select a record with null columns,these columns are filled with columns' value that are not null

See original GitHub issue

I am using myBatis in springboot web project, I got a table in my database like this: image

I also have a bean class(User) has fields just like the table’s structure:

public class User {
    public String loginId, loginPassword, name;
    public String enrollTime, gender, address, email;
    public User(String loginId, String loginPassword, String name, String gender, String address, String email) {
        this.loginId = loginId;
        this.loginPassword = loginPassword;
        this.name = name;
        this.gender = gender;
        this.address = address;
        this.email = email;
    }
    // getters and setters
}

myBatis mapper was written like this:

@Mapper
public interface UserMapper {
    @Select("select * from users where loginId=#{loginId}")
    public User GetUserByLoginId(@Param("loginId") String loginId);
}

When I call userMapper.GetUserByLoginId(“2”),myBatis give me the User object like this: image

It can be seen that the address and email fileds should have been null but was filled by other fileds’ value. I wonder what’s the problem with MyBatis, should I add some other annotation to fix this?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Paper-Foldingcommented, Jun 9, 2021

I know what’s going on.As I continue to test, a field in my model has a slightly different name from that in my database field, which leads to null value mis-match. Apologize for wasting your time.

0reactions
Paper-Foldingcommented, Jun 9, 2021

@Paper-Folding Hello, I think you mapper is wrong , mapper mapping you can check it.

No,mapper should be correct. This problem occurs in mysql database when several fields are varchar, and some of the records among these columns are null. I solved the problem for now by modifying default value of varchar fileds in my database from null to to EMPTY_STRING. As soon as I complete the current on-going project, I’ll provide a repro. (Sorry for my being busy now, MyBatis is a still a powerful tool for me.Thanks for all of your developers’ hard work!)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to SELECT Records With No NULL Values in MySQL
Use the MySQL engine to only grab records that you desire while excluding those with pesky NULL columns with the IS NOT NULL...
Read more >
How to Filter Rows without NULL in a column | LearnSQL.com
Do this by using the IS NOT NULL operator. Solution: SELECT name ,. price.
Read more >
How to display notnull rows and columns in a Python ...
To display not null rows and columns in a python data frame we are going to use different methods as dropna(), notnull(), loc[]....
Read more >
Select columns with NULL values only - sql server
This takes a list of values and returns the first non-null value. If you add all the column names to the list, then...
Read more >
SQL WHERE IS NULL | IS NOT NULL - Dofactory
WHERE IS NULL tests if a column has a NULL value. ... SELECT C.Id, FirstName, LastName, TotalAmount FROM Customer C LEFT JOIN [Order]...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found