Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updateByPrimaryKeySelective 会更新主键,报错 #119

Open
ebaecff opened this issue Dec 13, 2024 · 6 comments
Open

updateByPrimaryKeySelective 会更新主键,报错 #119

ebaecff opened this issue Dec 13, 2024 · 6 comments

Comments

@ebaecff
Copy link

ebaecff commented Dec 13, 2024

报错如下:

  ### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: modifying the partition value of rows is not allowed
  ### The error may exist in ItemMapper.java (best guess)
  ### The error may involve ItemMapper.updateByPrimaryKeySelective-Inline
  ### The error occurred while setting parameters
  ### SQL: UPDATE yahoo_items  SET  update_time = ?,   data_id = ? WHERE data_id = ?
  ### Cause: org.postgresql.util.PSQLException: ERROR: modifying the partition value of rows is not allowed

主键是这样配置的

    @Entity.Column(id = true, updatable = false)
    private String dataId;

应该如何配置调用 updateByPrimaryKeySelective 时把主键排除掉。
版本:
mybatisMapperVersion = "2.2.5"
mybatisSpringBootVersion = "3.0.4"

@abel533
Copy link
Contributor

abel533 commented Dec 13, 2024

@ebaecff
Copy link
Author

ebaecff commented Dec 16, 2024

对应生成sql的代码: https://github.com/mybatis-mapper/mapper/blob/9d2b0ab06c69819b14a70f7a9c7f6b0e1c721be6/mapper/src/main/java/io/mybatis/mapper/base/EntityProvider.java#L139C20-L139C33

对应获取更新列的代码: https://github.com/mybatis-mapper/provider/blob/00a0a7f6c30bd4c15ea596035672df2199e5999f/src/main/java/io/mybatis/provider/EntityTable.java#L416

可以在这里断点看看返回更新行的时候是否把 dataId 过滤掉了。

生成UPDATE XML SQL 中没有排除掉,Dubug可看到生成的 XML SQL
1111111

@ebaecff
Copy link
Author

ebaecff commented Dec 16, 2024

使用 updateByExampleSetValues 这个方式可以,符合预期,先用这种了,不过还是希望能使用这个 :updateByPrimaryKeySelective , 这个写起来更省事

@ebaecff
Copy link
Author

ebaecff commented Dec 16, 2024

dataId 这个字段,是公共的,多级继承,这个影响么?

@abel533
Copy link
Contributor

abel533 commented Dec 19, 2024

继承不影响,可以贴个实体的结构(含继承),我复现试试。

@ebaecff
Copy link
Author

ebaecff commented Dec 20, 2024

继承不影响,可以贴个实体的结构(含继承),我复现试试。

public class CommonDateBase {
    LocalDateTime insertTime = LocalDateTime.now();
    LocalDateTime updateTime = LocalDateTime.now();
}
public class CommonEntityUuidId extends CommonDateBase {
    @Entity.Column(id = true, updatable = false)
    private String dataId;
}
public class CommonEntity extends CommonEntityUuidId {
    String ahId;
    //xxx
}
@Entity.Table(value = "yahoo_items")
public class Item extends CommonEntity {
    String itemId;
    // xxx
}

实体继承如上,报错如上,调式信息如上!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants