最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

postgresql - Jakarta @Version sql update version error - Stack Overflow

programmeradmin2浏览0评论

All entity with @version

During saving, have next error

could not execute statement [Not found 3 param.] [update cons_data.e_fin_form set version=? where id=? and report_type=? and version=?]; SQL [update cons_data.e_fin_form set version=? where id=? and report_type=? and version=?]

2 tables with JoinTable, 1 with partition

@Entity
@Table(schema = "cons_data", name = "e_fin_form")
public class FinFormEntity extends BaseEntity implements Serializable {
    @Id
    @GeneratedValue
    private Long id;

    @Version
    private Integer version;

    @PartitionKey
    @Enumerated(EnumType.STRING)
    private ReportType reportType;

    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "form")
    private List<FormScanToFile> scans = new ArrayList<>();

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(
        schema = "cons_data",
        name = "j_fin_form_elimination",
        joinColumns = {
            @JoinColumn(name = "form_id", referencedColumnName = "id"),
            @JoinColumn(name = "report_type", referencedColumnName = "reportType")
        },
        inverseJoinColumns = @JoinColumn(name = "elimination_operation_id")
    )
    private Set<EliminationOperationEntity> eliminationOperations = new HashSet<>();
}
@Entity
@Table(schema = "cons_data", name = "e_elimination_operation")
public class EliminationOperationEntity extends BaseEntity {
    @Id
    @GeneratedValue
    private Long id;

    @Version
    private Integer version;

    @ManyToMany(mappedBy = "eliminationOperations", fetch = FetchType.LAZY)
    private Set<FinFormEntity> finForms = new HashSet<>();
}
@Service
public class SomeServiceClass {
    public void someMethod() {
        finForms.forEach(finFormEntity -> {
            finFormEntity.getEliminationOperations().add(eliminationOperation);
        });
        repository.saveAll(finForms);
    }
}

if remove version field it works

It works(version update) when saving scans

Dependencies

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.3.3'
    id 'io.spring.dependency-management' version '1.1.6'
}
java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(21)
    }
}
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
}
发布评论

评论列表(0)

  1. 暂无评论