删除的方法
public boolean deleteMusic(final String hql,final int id) {
try {
this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session){
SQLQuery sq=session.createSQLQuery(hql);
sq.setInteger(0,id);
return sq.executeUpdate();
}
});
bool = true;
} catch (Exception e) {
bool = false;
System.out.println("MusicDaoImpl......deleteMusic(String hql, int id)"+e);
}
return bool;
}
报的错误
Hibernate: delete from TMusic t where t.id = ?
2010-01-13 14:49:02,125 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 1064, SQLState: 42000
2010-01-13 14:49:02,125 ERROR [org.hibernate.util.JDBCExceptionReporter] - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't where t.id = 11' at line 1
MusicDaoImpl......deleteMusic(String hql, int id)org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute native bulk manipulation query; nested exception is org.hibernate.exception.SQLGrammarException: could not execute native bulk manipulation query用的是mysql数据库

解决方案 »

  1.   

    如果你HQL没有写错的话。
    MySQL version 貌似有问题!
      

  2.   

    在“'t where t.id = 11'”有hql语法错误
      

  3.   

    SQLQuery sq=session.createSQLQuery(hql); 
    你执行的是delete操作怎么创建一个查询语句类
      

  4.   

    直接在hql语句中传入参数试试
      

  5.   

    这是我的sql语句
    this.hql = "delete from TMusic t where t.id = ?";
    this.bool = this.musicDao.deleteMusic(this.hql,id);
      

  6.   

    知道什么原因了谢谢各位啊!
    SQLQuery sq=session.createSQLQuery(hql); 
    看错了要改成
    Query sq=session.createQuery(hql);
    就没有错误了!
    如果不改的话就
    写成sql语句也不会有问题
      

  7.   

    一开始我也以为是mySql的版本问题
      

  8.   

    session.createSQLQuery(hql); 是直接对数据库的操作(原生态的sql语句),并没有对对象操作
    所以你的并不是hql,而是sql;
    this.hql = "delete from table where id = ?"; 注意问号不要写出中文的了。
    如果用对象导航的hql就可以这样:
    hql = "delete from Table t where t.id = ?";
    session.createQuery(hql);