@Formular bug的解决方法

时间:2018-04-25 11:09:53

标签: java spring hibernate

我找到this错误的合适解决方法有点问题。

我需要用户的生日和下一个生日作为实体类中的持久字段。上述解决方法使用@ColumnTransfer,它也需要@Column注释。但是没有专栏" nextBirthday"或类似的东西,并引用birthdate工作不明确(列含糊不清)。

我原来的User课程是:

@Entity
public class User {
    @ID
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "USERS_ID_GENERATOR")
    private long id;

    @Column
    @Temporal(TemporalType.DATE)
    private Date birthdate;

    @Formula("add_months(birthDate, floor(months_between(sysdate - 1, birthDate) /12 + 1) * 12)")
    private Date nextBirthday;

    // More Fields
}

我第一次尝试使用@ColumnTransformer

@Entity
public class User {
    @ID
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "USERS_ID_GENERATOR")
    private long id;

    @Column
    @Temporal(TemporalType.DATE)
    private Date birthdate;

    @Column("birthdate")
    @ColumnTransformer(read = "add_months(birthDate, floor(months_between(sysdate - 1, birthDate) /12 + 1) * 12)")
    private Date nextBirthday;

    // More Fields
}

这不起作用,因为有两个字段引用了生日。

有没有人知道解决方法而不参考专栏?

0 个答案:

没有答案
相关问题