【问题标题】:Spring Data error Caused by: org.hibernate.QueryException: could not resolve propertySpring Data 错误原因:org.hibernate.QueryException:无法解析属性
【发布时间】:2018-01-03 16:25:50
【问题描述】:

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

原因:org.hibernate.QueryException:无法解析属性:版本: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】:

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

    来自规范:

    11.1.38 MappedSuperclass 注解

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

    【讨论】:

      猜你喜欢
      • 2023-03-17
      • 2013-07-25
      • 2014-02-24
      • 1970-01-01
      • 1970-01-01
      • 2017-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多