我在休眠时面临更新 hql 查询的问题。
这是我的以下课程:
--session configuration
ExamResults examResults = new ExamResults();
examResults.setTitle("cbse board jee");
examResults.setId(2);
String hql = "UPDATE EXAMRESULTS SET TITLE=:TITLE WHERE ID=:ID";
Query query = session.createQuery(hql);
query.setParameter("TITLE", examResults.getTitle());
query.setParameter("ID", examResults.getId());
int result = query.executeUpdate();
System.out.println("Rows Effected=>"+result);
session.save(examResults);
tx.commit();
}
}
在运行课程时,我收到以下异常:
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: EXAMRESULTS is not mapped [UPDATE EXAMRESULTS SET TITLE=:TITLE WHERE ID=:ID]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)
...
我的豆类也在这里:
@Entity
@Table(name="EXAMRESULTS")
public class ExamResults implements Serializable{
private int id;
private String title;
private String body1;
private String body2;
private Date resultdate;
private String affiliation;
private int isactive;
private String url;
private String imageurl;
//private CommonsMultipartFile imageurlimg;
private String metatitle;
private String metadescription;
private String metakeywords;
private Date createddate;
--getters & setters
解决问题的正确方法应该是什么?