我的应用程序在启动时抛出错误
引起: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;
}
}
是否无法引用超类属性?
答案 0 :(得分:1)
ModelObject必须使用@MappedSuperclass注释,JPA中没有自动继承
来自规范:
11.1.38 MappedSuperclass注释
MappedSuperclass注释指定一个类,其映射信息应用于从其继承的实体。映射的超类没有为其定义单独的表。