我正在使用注释使用hibernate 4.3,但没有任何映射问题。我迁移到了hibernate 5.1,并且遇到了映射问题。
我检查我的DAO,并且查询使用的名称与我的实体类的名称相同,这是每个人都建议的解决方案。
这是我的实体类
@Entity
@Table(name = "__maintenance", uniqueConstraints = @UniqueConstraint(columnNames = "name"))
public class __Maintenance implements java.io.Serializable {
private static final long serialVersionUID = 7217691607923908432L;
private int idMaintenance;
private int version;
private String storyNumber;
private String name;
private Date startDate;
private Date endDate;
private String comments;
public __Maintenance() {
this.version = 1;
}
@Deprecated
public __Maintenance(String storyNumber, String name) {
this.storyNumber = storyNumber;
this.name = name;
}
@Deprecated
public __Maintenance(String storyNumber, String name, Date startDate, Date endDate, String comments) {
this.storyNumber = storyNumber;
this.name = name;
this.startDate = startDate;
this.endDate = endDate;
this.comments = comments;
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "idMaintenance", unique = true, nullable = false)
public int getIdMaintenance() {
return this.idMaintenance;
}
public void setIdMaintenance(int idMaintenance) {
this.idMaintenance = idMaintenance;
}
@Column(name = "version", nullable = false)
public int getVersion() {
return this.version;
}
public void setVersion(int version) {
this.version = version;
}
@Column(name = "story_number", nullable = false, length = 50)
public String getStoryNumber() {
return this.storyNumber;
}
public void setStoryNumber(String storyNumber) {
this.storyNumber = storyNumber;
}
@Column(name = "name", unique = true, nullable = false, length = 50)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "start_datetime", length = 19)
public Date getStartDate() {
return this.startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "end_datetime", length = 19)
public Date getEndDate() {
return this.endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
@Column(name = "comments", length = 65535)
public String getComments() {
return this.comments;
}
public void setComments(String comments) {
this.comments = comments;
}
这是我的查询
String query = "";
query += "select m from __Maintenance m";
query += " where m.name = :name ";
query += " order by ";
query += " m.startDate desc, m.idMaintenance desc";
return super.list(query, "name", name);
}
以下是我的例外
由以下原因引起:org.hibernate.hql.internal.ast.QuerySyntaxException:__Maintenance未映射[从__Maintenance m中选择m,其中m.name =:name由m.startDate desc,m.idMaintenance desc顺序排列] 在org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:79) 在org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103) 在org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:218) 在org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:142) 在org.hibernate.engine.query.spi.HQLQueryPlan。(HQLQueryPlan.java:115) 在org.hibernate.engine.query.spi.HQLQueryPlan。(HQLQueryPlan.java:76)
答案 0 :(得分:1)
该表似乎在配置中丢失。该表是在persistence.xml还是javaconfig文件中声明的?