Spring Data error由以下原因引起:org.hibernate.QueryException:无法解析属性

问题描述 投票:0回答:1

我的应用程序在启动时抛出错误

引起:org.hibernate.QueryException:无法解析属性:version of org.mycompany.system.model.Code

我的存储库方法

@Query("SELECT NEW org.mycompany.util.CodeVO(c.id,  c.description,c.version) FROM Code c where  c.groupName = :groupName")
    List<CodeVO> getByGroupName(@Param("groupName") String groupName);

基类

public abstract class ModelObject<ID extends Serializable> implements Serializable {

    @Column(nullable = false, length = 100)
    private String createdBy;

    @Column(nullable = false)
    private LocalDateTime createdTime = LocalDateTime.now();

    @Version
    private int version;

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }
    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

}

子类

 @Entity
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "groupName", "description" }) })
public class Code extends ModelObject<Long> {


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

    @Column
    @NotBlank
    private String description;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
}

是不是可以引用超类属性?

java hibernate jpa spring-data spring-data-jpa
1个回答
1
投票

ModelObject必须使用@MappedSuperclass注释,JPA中没有自动继承

从规格:

11.1.38 MappedSuperclass注释

MappedSuperclass注释指定一个类,其映射信息应用于从其继承的实体。映射的超类没有为其定义单独的表。

© www.soinside.com 2019 - 2024. All rights reserved.