log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment). log4j:WARN Please initialize the log4j system properly. Hibernate: delete from Sort_table where Sid=10 org.hibernate.exception.ConstraintViolationException: could not execute update query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:84) at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:334) at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:209) at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1126) at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94) 那个是类名,QxEntity应该是这样的,上面传错了.......
String hql="delete qxEntity qx where qx.qxid=?";
抛出的错误是这样的query must begin with SELECT or FROM: delete 吗? 如果是 的话,在hibernate的配置文件看看有没有 <property name="hibernate.query.factory_class"> org.hibernate.hql.classic.ClassicQueryTranslatorFactory </property> 有的话去掉就可以了
log4j:WARN Please initialize the log4j system properly.
Hibernate: delete from Sort_table where Sid=10
org.hibernate.exception.ConstraintViolationException: could not execute update query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:84)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:334)
at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:209)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1126)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
那个是类名,QxEntity应该是这样的,上面传错了.......
如果是 的话,在hibernate的配置文件看看有没有
<property name="hibernate.query.factory_class">
org.hibernate.hql.classic.ClassicQueryTranslatorFactory
</property>
有的话去掉就可以了
请求帮忙!!!
前 然后载提交实务看一下
try{
Session session=HibernateSessionFactory.getSession();
session.beginTransaction();
context.setId(id);
session.delete(context);
session.getTransaction().commit();
session.close();
return true;
}catch(Exception e){
return false;
}
}
delete 语句可以的,我用过。