Spring Boot org.hibernate.id.IdentifierGenerationException:此类的ID必须在调用save()之前手动分配

时间:2019-02-11 00:23:44

标签: java spring-boot jpa spring-data-jpa

我的警报类别

  @Entity
   public class Alert {

    @Id
    @Column(name = "u_id")
    private String u_id;
    @Embedded
    private Reading reading;

    @Column(insertable = false, updatable = false)
    String vin;

    private String priority;

    public String getU_id() {
        return u_id;
    }

    public void setU_id(String u_id) {
        this.u_id = u_id;
    }

    public String getPriority() {
        return priority;
    }

    public void setPriority(String priority) {
        this.priority = priority;
    }


    public Reading getVehicleReading() {
        return reading;
    }

    public void setVehicleReading(Reading vehicleReading) {
        this.reading = vehicleReading;
    }
}

我的ReadingsServiceImplementation类的片段,其中触发了规则:

public void checkAlert(Reading reading){
    Alert alert = new Alert();
    UUID uuid = UUID.randomUUID();
    String randomUUIDString = uuid.toString();
    KieSession kieSession = kieContainer.newKieSession("rulesSession");
    kieSession.setGlobal("alert", alert);
    kieSession.insert(reading);
    kieSession.fireAllRules();
    kieSession.dispose();
    alert.setU_id(randomUUIDString);
    alert.setVehicleReading(reading);
    alertRepository.save(alert);
}

如上所述,我尝试了身份生成和ID的手动生成。为什么我得到手动生成ID的错误?

尝试了长id以及在类似问题中提到的问题,但没有解决。

0 个答案:

没有答案