Struts 2 ile yeni tanışan birisi olarak, geliştirmeye çalıştığım basit bir CMS yazılımında bir hata ile karşılaştım. Bir site yöneticisinin durumunu “Aktif - Pasif” yapan methodum “query must begin with SELECT or FROM: update” hatası verdi. Kod aşağıdadır…
public void updateStatus(Integer id, String status) throws Exception {
int rowCount=0;
log.info(”update yonetici. “);
try {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
String hqlcmd = “update managers set status = :status where id = :id”;
Query query = session.createQuery(hqlcmd);
query.setString(”status”,status);
query.setInteger(”id”,id);
rowCount = query.executeUpdate();
if (rowCount<1)
throw new Exception(”cannot update Managers table with id “+ id);
} catch (RuntimeException re) {
log.error(”Hata: update yonetici. “, re);
throw re;
}
}
yukarıdaki method “query must begin with SELECT or FROM: update” hatası veriyordu dediğim gibi. araştırmalarım ve denemelerim sonucunda bu sorunu aşağıdaki kodu yazarak aştım,
public void updateStatus(Integer id, String status) throws Exception {
int rowCount=0;
log.info(”update yonetici. “);
try {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
String hqlcmd = “update mesken.web.kaptan.yonetici.Yonetici u set status = :status where id = :id”;
Query query = session.createQuery(hqlcmd);
query.setString(”status”,status);
query.setInteger(”id”,id);
rowCount = query.executeUpdate();
if (rowCount<1)
throw new Exception(”cannot update Managers table with id “+ id);
} catch (RuntimeException re) {
log.error(”Hata: update yonetici. “, re);
throw re;
}
}
iki method arasındaki farkı gördünüzmü??
“update mesken.web.kaptan.yonetici.Yonetici u set status = :status where id = :id” hql cümleciğinde Yonetici pojosunun tam yolunu verdiğim zaman düzeldi.


bu problemi yasiyorsaniz, config file da asagida belirtilen setting i yapmalisiniz.
bilg.
org.hibernate.hql.ast.ASTQueryTranslatorFactory
yani hibernate.query.factory_class property si icin org.hibernate.hql.ast.ASTQueryTranslatorFactory set edin