确认
- [X] 我的版本是最新版本, 我的版本号与 version 相同, 并且项目里无依赖冲突
- [X] 我已经在 issue 中搜索过, 确认问题没有被提出过
- [X] 我已经修改标题, 将标题中的 描述 替换为遇到的问题
当前程序版本
3.5.2
问题描述
已经使用3.5.5版本,也不行。找不到相关问题
具体代码如下: @Override public void testUpdateUser(int id, String address) { TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""), User.class); boolean update = lambdaUpdate().eq(User::getId, id).set(User::getAddress, address).update(); System.out.println(update); }
@Override
public void testUpdateDomanUser(User i,User rs) {
TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""), User.class);
boolean update = lambdaUpdate().eq(User::getId, i.getId()).set(User::getAddress,i.getAddress()).set(User::getAge,i.getAge()).update(rs);
System.out.println(update);
}
@Test
public void testupdate(){
int id = 5;
String address = "湛江";
userService.testUpdateUser(id,address);
queryUser(id);
}
@Test
public void testUpdateUser(){
User i = new User();
i.setId(6);
i.setAddress("test11111");
i.setAge(45);
User user2 = new User();
user2.setId(6);
user2.setAge(40);
List
update()是正常的,当update(T entity)会出现异常。要set的字段,在SQL中会出现两次,一次是SQL对象获取到的值,一次是要更新的值
详细堆栈日志
JDBC Connection [org.postgresql.jdbc.PgConnection@50fb33a] will not be managed by Spring
==> Preparing: SELECT id,user_name,password,name,age,email,address FROM tb_user WHERE (id = ?)
==> Parameters: 6(Integer)
<== Columns: id, user_name, password, name, age, email, address
<== Row: 6, user6, pass6, David Wilson, 40, david.wilson@example.com, 1313 Cedar Street
<== Total: 1
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6b2e46af]
User(id=6, userName=user6, password=pass6, name=David Wilson, age=40, email=david.wilson@example.com, address=1313 Cedar Street)
This primary key of "id" is primitive !不建议如此请使用包装类 in Class: "com.gbase.mpdemo.domain.User"
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4596f8f3] was not registered for synchronization because synchronization is not active
JDBC Connection [org.postgresql.jdbc.PgConnection@50fb33a] will not be managed by Spring
==> Preparing: UPDATE tb_user SET user_name=?, password=?, name=?, age=?, email=?, address=?, address=?,age=? WHERE (id = ?)
==> Parameters: user6(String), pass6(String), David Wilson(String), 40(Integer), david.wilson@example.com(String), 1313 Cedar Street(String), test11111(String), 45(Integer), 6(Integer)
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4596f8f3]
org.springframework.jdbc.BadSqlGrammarException:
### Error updating database. Cause: org.postgresql.util.PSQLException: ERROR: multiple assignments to same column "address"
### The error may exist in com/gbase/mpdemo/mapper/UserMapper.java (best guess)
### The error may involve com.gbase.mpdemo.mapper.UserMapper.update-Inline
### The error occurred while setting parameters
### SQL: UPDATE tb_user SET user_name=?, password=?, name=?, age=?, email=?, address=?, address=?,age=? WHERE (id = ?)
### Cause: org.postgresql.util.PSQLException: ERROR: multiple assignments to same column "address"
; bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: ERROR: multiple assignments to same column "address"
Comment From: huage0524
mysql是正常的,postgres会异常
Comment From: huage0524
JDBC Connection [com.mysql.jdbc.JDBC4Connection@2a369e14] will not be managed by Spring
==> Preparing: SELECT id,user_name,password,name,age,email,address FROM tb_user WHERE (id = ?)
==> Parameters: 6(Integer)
<== Columns: id, user_name, password, name, age, email, address
<== Row: 6, user6, pass6, David Wilson, 45, david.wilson@example.com, test11111
<== Total: 1
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5e1d03d7]
User(id=6, userName=user6, password=pass6, name=David Wilson, age=45, email=david.wilson@example.com, address=test11111)
This primary key of "id" is primitive !不建议如此请使用包装类 in Class: "com.gbase.mpdemo.domain.User"
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3c3c4a71] was not registered for synchronization because synchronization is not active
JDBC Connection [com.mysql.jdbc.JDBC4Connection@2a369e14] will not be managed by Spring
==> Preparing: UPDATE tb_user SET user_name=?, password=?, name=?, age=?, email=?, address=?, address=?,age=? WHERE (id = ?)
==> Parameters: user6(String), pass6(String), David Wilson(String), 45(Integer), david.wilson@example.com(String), test11111(String), CN GZ(String), 45(Integer), 6(Integer)
<== Updates: 1
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3c3c4a71]
true
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3d96fa9e] was not registered for synchronization because synchronization is not active
JDBC Connection [com.mysql.jdbc.JDBC4Connection@2a369e14] will not be managed by Spring
==> Preparing: SELECT id,user_name,password,name,age,email,address FROM tb_user WHERE (id = ?)
==> Parameters: 6(Integer)
<== Columns: id, user_name, password, name, age, email, address
<== Row: 6, user6, pass6, David Wilson, 45, david.wilson@example.com, CN GZ
<== Total: 1
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3d96fa9e]
User(id=6, userName=user6, password=pass6, name=David Wilson, age=45, email=david.wilson@example.com, address=CN GZ)
这是mysql的堆栈
Comment From: miemieYaho
sql生成和数据库无关,wrapper手动set的字段就不要在entity里再次这个字段出现值
Comment From: huage0524
这里跟数据库有关,mysql支持重复绑定,postgres不支持。只能修改代码了吗?
Comment From: miemieYaho
mp不会给你去重,自己改代码吧
Comment From: huage0524
好的,谢谢!