0
我正在使用休眠4.3.10。根據hibernate文檔(13.4),應該支持DML樣式更新。任何人都可以指出我做錯了什麼?我有以下代碼:使用休眠批量更新行
Session session = CurrentJobContextUtil.getCurrentContext().getSession();
Query query = session.createQuery("update Survey s set s.state = :newState where s.endDate < :time and s.state != :newState");
query.setParameter("newState",newState);
query.setDate("time", time);
int count = (int)query.uniqueResult();
我得到異常:
org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML operations [update com.customerconnect.jobmanager.data.model.Survey s set s.state = :newState where s.endDate < :time]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.errorIfDML(QueryTranslatorImpl.java:318)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:369)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:236)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1300)
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
at org.hibernate.internal.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:966)
at com.customerconnect.jobmanager.data.dao.SurveyDAOImpl.updateSurveyState(SurveyDAOImpl.java:26)
at com.customerconnect.jobmanager.CCJobDataSvc.expireSurveys(CCJobDataSvc.java:510)
at com.customerconnect.jobmanager.jobs.SurveyJobs.expireSurveys(SurveyJobs.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)