当冲突不是主键时使用Upsert记录(使用Hibernate和Postgres)

Jpa / hibernate和Postgres新手问题在这里。

我有一个这样定义的数据库实体:

public class accountEntity{

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "account_number",nullable = false)
    private String accountNumber;

    .... few other columns including createdAt,updatedAt and few other account related fields 

}

在我的代码中,使用JpaRepository,我想执行以下操作:

accountEntity acc = new accountEntity();
acc.setaccountNumber(123);
accountRepository.upsert(acc)

我知道我需要为类似的事情定义自己的sql 如果已经存在具有指定accountNumber的帐户,那么执行upsert的正确sql是什么(我将需要更新大多数字段,但不更新createdAt字段) 另外,关于批量更新的类似问题

xuanxixuan 回答:当冲突不是主键时使用Upsert记录(使用Hibernate和Postgres)

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3163327.html

大家都在问