Mybatis Insert PK manually

I am trying to single insert data into table with assigned PK. Manually assiging PK.

XML file

<insert id = "insertStd" parameterType = "com.org.springboot.dao.StudentMapper" useGeneratedKeys = "false" keyProperty = "insertStd.id", keyColumn = "id">
      INSERT INTO STUDENT (ID, NAME, BRANCH, PERCENTAGE, PHONE, EMAIL ) 
      VALUES (ID=#{insertStd.id}, NAME=#{insertStd.name}, BRANCH=#{insertStd.branch}, PERCENTAGE=#{insertStd.percentage}, PHONE=#{insertStd.phone}, EMAIL =#{insertStd.email});

   </insert>

Service call method

public boolean saveStudent(Student student){
    LOGGER.info("Student object save");
    int savedId= studentMapper.insertStd(student);
}

Log file

org.springframework.jdbc.badsqlgrammarexception
### Error updating database Causes: cause org.postgresql.util.psqlexception error column id does not exist
HINT: There is a column named "id" in the table "student" but it can't be referenced from this part of the query. 
Position 200
### Error may exist in file [c:\.....\StudentMapper.xml]
### Error may involve in com.org.springboot.dao.StudentMapper.insertStd-InLine
### The error occurred while setting parameters
### SQL INSERT INTO STUDENT (ID, NAME, BRANCH, PERCENTAGE, PHONE, EMAIL ) 
  VALUES (ID=?, NAME=?,BRANCH=?, PERCENTAGE=?, PHONE=?, EMAIL=?);
### cause org.postgresql.util.psqlexception ERROR column "id" doesn't exist. //It does it did worked with JPA id assigned manually.
### There is a column named "ID" in the table "STUDENT", Bbut it cannot be referenced from the part of the query. 


Read more here: https://stackoverflow.com/questions/66522873/mybatis-insert-pk-manually

Content Attribution

This content was originally published by Surya Chandra at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: