如果调用类使用lombok @Data注释,则hibernate 4.x无法加载超类实体列名

时间:2018-03-22 20:52:22

标签: java sql hibernate jpa lombok

您好我正在使用带有@Data注释的实体类的lombok api,它扩展了审计类(公共列),它是带有@MappedSuperclass注释的简单抽象类。但是当hibernate-jpa加载时,它不会拾取列名,而是拾取实际的成员变量名。

@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "TEST_TYPES", schema = "TESTER")
@EqualsAndHashCode(callSuper = false, of = {"id"})
public class TestEntity extends AuditEntity {
    @Id
    @Column(name = "TYPE_ID")
    private Short id;

    @Column(name = "NAME")
    private String name;    
}


    @MappedSuperclass
public abstract class AuditEntity implements Serializable {
    private static final long serialVersionUID = 3487394229267512541L;
    private String createdBy;
    private Date createdDate;

    @Column(name = "CREATE_ID", length = 40)
    public String getCreatedBy() {
        return this.createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "CREATED_DATE", length = 7)
    public Date getCreatedDate() {
        return this.createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

}

问题: Hibernate抛出这个错误.. 引起:java.sql.SQLSyntaxErrorException:ORA-00904:“TESTPROJJU0 _”。“CREATEDBY”:标识符无效

预期: hibernate应该选择列名称,即“CREATED_BY”,但它正在拾取“createdby”

我感谢任何建议/帮助。

2 个答案:

答案 0 :(得分:0)

这可能与JPA的命名策略有关。设置属性

spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

应该采用您提供的实际列名。

答案 1 :(得分:0)

您没有使用@Column注释指定名称。