Reputation: 590
I was working with hibernate 4.3 using annotations and I did not had any mapping issue.I migrated to hibernate 5.1 and I have mapping issues.
I check my DAO and query is using same name as that of my entity class that is the solution everyone suggest.
This is my entity class
@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;
}
And this is my query
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);
}
Following is my exception
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: __Maintenance is not mapped [select m from __Maintenance m where m.name = :name order by m.startDate desc, m.idMaintenance desc] at org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:79) at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:218) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:142) at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:115) at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:76)
Upvotes: 1
Views: 94
Reputation: 41
It seems the table is missing in the configuration. Is the table declared in persistence.xml or javaconfig file?
Upvotes: 1