Hibernate中使用truncate tasble,代码如下:public Object doInHibernate(Session session)
       throws HibernateException, SQLException {
     session.createSQLQuery("truncate table customers").executeUpdate();
        }使用postgresql-7.3.1版本的数据库报错:
Exception in thread "timerFactory" org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not execute native bulk manipulation query; uncategorized SQLException for SQL [truncate table tbl_easynet_alert_info]; SQL state []; error code [0]; ERROR:  TRUNCATE TABLE cannot run inside a transaction block; nested exception is org.postgresql.util.PSQLException: ERROR:  TRUNCATE TABLE cannot run inside a transaction block
Caused by: org.postgresql.util.PSQLException: ERROR:  TRUNCATE TABLE cannot run inside a transaction block但是使用postgresql-8.3版本的数据,可以正常运行不会报错,这是什么原因,有没有什么解决办法啊,求助求助!!!

解决方案 »

  1.   

    估计是1个限制,在7.3.1中事务块内不能运行TRUNCATE   TABLE ,只有升级
      

  2.   

    改成delete from customers 
      

  3.   


    刚看了postgresql的官方文档,上面写TRUNCATE cannot be executed inside a transaction block (BEGIN/COMMIT pair), because there is no way to roll it back.从7.4版本开始就没有这个问题了,如果不升级数据库的话,就只能改成"delete from"了, 哎