Reputation: 1816
My application throws the error while starting
Caused by: org.hibernate.QueryException: could not resolve property: version of: org.mycompany.system.model.Code
My repository method
@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);
Base class
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;
}
}
Sub class
@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;
}
}
is it not possible to refer superclass properties?
Upvotes: 2
Views: 2393
Reputation: 36103
ModelObject must be annotated with @MappedSuperclass there is no automatic inheritance in JPA
From the spec:
11.1.38 MappedSuperclass Annotation
The MappedSuperclass annotation designates a class whose mapping information is applied to the entities that inherit from it. A mapped superclass has no separate table defined for it.
Upvotes: 4