-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: hibernate hql ERROR: Not supported for DML operations
PostPosted: Fri Sep 21, 2012 12:36 am 
Newbie

Joined: Fri Sep 21, 2012 12:13 am
Posts: 7
This is a DAO class method. I am calling this method in controller for multiple updates for student roster table in oracle displayed in view using hibernate and spring mvc. I can't add this update to db. Any comments or suggestion would be appreciated.
Code:
public List<Object[]> rosterGrdUpdate(String stuBunValue, String stuGrdValue, String pcID, String crsCd) {
java.util.Date today = new java.util.Date();
Date Date_toDay = new java.sql.Date(today.getTime());
String modifyFlagUpdate = "U";
String modifyFlagWh = "N";
Query querySt  = null;
String sql1 = "update WgRoster wr set wr.grade= :gr, wr.modify_flag= :mf, wr.grade_date= :gd, wr.user_id= :ud" +
" where wr.stubun= :stb and wr.crs_cd= :cr and wr.modify_flag !=  :mfu";
querySt  = session.createQuery(sql1);
querySt.setParameter("gr", stuGrdValue);
querySt.setParameter("mf", modifyFlagUpdate);
querySt.setParameter("gd", Date_toDay);
querySt.setParameter("ud", pcID);
querySt.setParameter("stb", stuBunValue);
querySt.setParameter("cr", crsCd);
querySt.setParameter("mfu", modifyFlagWh); 
int res = querySt.executeUpdate(); 
return  (List<Object[]>)querySt.list();


Top
 Profile  
 
 Post subject: Re: hibernate hql ERROR: Not supported for DML operations
PostPosted: Mon Sep 24, 2012 9:49 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Can you please post the Error with full-stacktrace, thanks.


Top
 Profile  
 
 Post subject: Re: hibernate hql ERROR: Not supported for DML operations
PostPosted: Mon Sep 24, 2012 11:33 am 
Newbie

Joined: Fri Sep 21, 2012 12:13 am
Posts: 7
thanks for looking into this pb00067. Below are the Error with full-stacktrace

Code:
update_roster1_post****Ln544**stuGrdcnt : 2
update_roster1_post****Ln578**stuGrades :jc11113
update_roster1_post****Ln609**
WgRosterDAO**Ln148**Date_toDay2012-09-24
WgRosterDAO**Ln185**UPDATE  stuGrdValue:A- modifyFlagUpdate:U todayStr:2012-09-24 pcID:0:0:0:0:0:0:0:1
Unknown entity: org.hibernate.impl.QueryImpl
WgRosterDAO**Ln180*************BACK TO CONTROLLER ********************
Sep 24, 2012 11:29:51 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/webtestspring] threw exception [Request processing failed; nested exception is org.hibernate.hql.QueryExecutionRequestException: Not supported for DML operations [update webgrade.spring.domain.WgRoster wr set wr.grade=?, wr.modify_flag=?, wr.grade_date=?, wr.user_id=? where wr.stubun=? and wr.crs_cd=? and wr.modify_flag != ?]] with root cause
org.hibernate.hql.QueryExecutionRequestException: Not supported for DML operations [update webgrade.spring.domain.WgRoster wr set wr.grade=?, wr.modify_flag=?, wr.grade_date=?, wr.user_id=? where wr.stubun=? and wr.crs_cd=? and wr.modify_flag != ?]
   at org.hibernate.hql.ast.QueryTranslatorImpl.errorIfDML(QueryTranslatorImpl.java:297)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:346)
   at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1149)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
   at webgrade.spring.dao.WgRosterDAO.rosterGrdUpdate(WgRosterDAO.java:263)
   at webgrade.spring.dao.WgRosterDAO$$FastClassByCGLIB$$aa7aef05.invoke(<generated>)
   at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
   at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:688)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621)
   at webgrade.spring.dao.WgRosterDAO$$EnhancerByCGLIB$$dbd55f75.rosterGrdUpdate(<generated>)
   at webgrade.spring.controller.WGController.update_roster1_post(WGController.java:610)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:601)
   at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
   at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
   at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
   at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
   at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
   at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
   at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
   at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
   at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
   at java.lang.Thread.run(Thread.java:722)


Top
 Profile  
 
 Post subject: Re: hibernate hql ERROR: Not supported for DML operations
PostPosted: Tue Sep 25, 2012 5:28 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Ok, from the stacktace I see, that the exception does not rise when you are actually doing the update

Code:
int res = querySt.executeUpdate(); 


but when you are calling

Code:
(List<Object[]>)querySt.list();


You can call query.list only on select queries.
On update-queries (DML operations) indeedit is enough to call query.executeUpdate().
The returned int tells you how many records were been affected by the update.


Top
 Profile  
 
 Post subject: Re: hibernate hql ERROR: Not supported for DML operations
PostPosted: Tue Sep 25, 2012 11:46 am 
Newbie

Joined: Fri Sep 21, 2012 12:13 am
Posts: 7
thanks again. I am trying to capture the values as a list from the controller which is captured from jsp view from user. I am passing the values to the DAO and rosterGrdUpdate(String stuBunValue, String stuGrdValue, String pcID, String crsCd) method in DAO i posted earlier is doing the update. Therefore, I am using list as a return type.

Also, I wanted to print the updated value to the next view screen. I wanted to return the updated values to the controller and pass them to the JSP.

Any thought on this?

below the code excerpt for controller to capture the values from the user and pass to the DAO and return to the JSP to get the updated values.

Code:
List<Object[]> stuGradesUpdate = null;
Vector stuBun = new Vector(stuGrdcnt);          
Vector grade = new Vector(stuGrdcnt);
Vector comment = new Vector(stuGrdcnt);
int i=0;
while ( i< stuGrdcnt  ){
stuBunValue = parser.getStringParameter(stuBunid +i,"unknown");
if ( stuBunValue == null ) {
stuBunValue = "0" ;
}
if(!stuBunValue.equals("unknown")) session.setAttribute(stuBunid +i, stuBunValue);
stuBun.add(session.getAttribute(stuBunid +i));
System.out.println("update_roster1_post****Ln578**stuGrades :" + stuBun.get(i).toString());
stuGrdValue = parser.getStringParameter(stuGrd +i,"unknown");
if ( stuGrdValue == null ) {
stuGrdValue = "0" ;
}
if(!stuGrdValue.equals("unknown")) session.setAttribute(stuGrd +i, stuGrdValue);
grade.add(session.getAttribute(stuGrd +i));
grdCommentValue = parser.getStringParameter(grdComment +i,"unknown");
if ( grdCommentValue == null ) {
grdCommentValue = "0" ;
}
if(!grdCommentValue.equals("unknown"))
{
session.setAttribute(grdComment +i, grdCommentValue);
}else if ( grdCommentValue == null ){
session.setAttribute(grdComment +i, "0");
}
comment.add(session.getAttribute(grdComment +i));
System.out.println("update_roster1_post****Ln609**");
stuGradesUpdate = rosterDAO.rosterGrdUpdate(stuBun.get(i).toString() ,grade.get(i).toString(),remote_addr, crs_cd);

System.out.println("update_roster1_post****Ln611**stuGrades :"  + stuBunid +i +":"+ stuBun.get(i).toString() +";"+ stuGrd +i+":"+grade.get(i).toString()+";"+grdComment+i+comment.get(i).toString() + "***" );

ModelAndView mavUR = new ModelAndView("update_roster1");
mavUR.addObject("UPDATED_GRADES", stuGradesUpdate);


Top
 Profile  
 
 Post subject: Re: hibernate hql ERROR: Not supported for DML operations
PostPosted: Wed Sep 26, 2012 4:02 pm 
Newbie

Joined: Fri Sep 21, 2012 12:13 am
Posts: 7
i changed the rosterGrdUpdate() to void and still no DB update.
below is the console print:

Code:
update_roster1_post****Ln544**stuGrdcnt : 2
update_roster1_post****Ln578**stuGrades :jc11113
update_roster1_post****Ln609**
WgRosterDAO**Ln148**Date_toDay2012-09-26
WgRosterDAO**Ln185**UPDATE  stuGrdValue:B modifyFlagUpdate:U todayStr:2012-09-26 pcID:0:0:0:0:0:0:0:1
Hibernate: update WG_ROSTER set grade=?, modify_flag=?, grade_date=?, user_id=? where stubun=? and crs_cd=? and modify_flag<>?
querySt:QueryImpl(update WgRoster wr set wr.grade=?, wr.modify_flag=?, wr.grade_date=?, wr.user_id=? where wr.stubun=? and wr.crs_cd=? and wr.modify_flag != ?)
UPDATE  stuGrdValue:B modifyFlagUpdate:U todayStr:2012-09-26 pcID:0:0:0:0:0:0:0:1
WHERE  stuBunValue:jc11113 crsCd:0135 modifyFlagWh:N
WgRosterDAO**Ln169**Command successfully executed....
WgRosterDAO**Ln170**Number of records effected due to update query0
WgRosterDAO**Ln180*************BACK TO CONTROLLER ********************
update_roster1_post****Ln578**stuGrades :jj11112
update_roster1_post****Ln609**
WgRosterDAO**Ln148**Date_toDay2012-09-26
WgRosterDAO**Ln185**UPDATE  stuGrdValue:B modifyFlagUpdate:U todayStr:2012-09-26 pcID:0:0:0:0:0:0:0:1
Hibernate: update WG_ROSTER set grade=?, modify_flag=?, grade_date=?, user_id=? where stubun=? and crs_cd=? and modify_flag<>?
querySt:QueryImpl(update WgRoster wr set wr.grade=?, wr.modify_flag=?, wr.grade_date=?, wr.user_id=? where wr.stubun=? and wr.crs_cd=? and wr.modify_flag != ?)
UPDATE  stuGrdValue:B modifyFlagUpdate:U todayStr:2012-09-26 pcID:0:0:0:0:0:0:0:1
WHERE  stuBunValue:jj11112 crsCd:0135 modifyFlagWh:N
WgRosterDAO**Ln169**Command successfully executed....
WgRosterDAO**Ln170**Number of records effected due to update query0
WgRosterDAO**Ln180*************BACK TO CONTROLLER ********************
@@@@@@@@@@@@@@@@@@ update_roster1_post @@@@@@@@@@@ Ln659  @@@ TRANSFER TO JSP @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
sectionInfo-JSP*Ln:174:webgrade.spring.domain.WGSection@f0bb05[crs_cd=0135,div_cd=G,discipln_cd=14,crs_num=9800,sec_num=S2DA,crse_descr=INTENSIVE SURVEY LAW,password=abc123,init_psw_flag=N,send_to_registrar=N,send_date=<null>,confirm_number=<null>,send_to_sims=<null>,dept_cd=LAW,alt_dept_cd=<null>,alt_dept1_cd=<null>,alt_dept2_cd=<null>,paper_roster=N,credits=4,login_count=0,login_time=1990-01-01 00:00:00.0,signature=<null>,emailed=false]
crsCd-JSP*Ln:158:0135


Top
 Profile  
 
 Post subject: Re: hibernate hql ERROR: Not supported for DML operations
PostPosted: Thu Sep 27, 2012 7:45 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
Also, I wanted to print the updated value to the next view screen. I wanted to return the updated values to the controller and pass them to the JSP.

Any thought on this?


What you are practically doing is a bulk update.
Bulk updates are executed directly on the database without that the hibernate persistence context perceives the relevant changes.
If you reread the entities with a query after having done the bulk update,
then these entity objects don't will reflect the changes you did because of the repeatable-read behavior of hibernate persistence context.
To do this you must either clear the whole persistent context or detach all concerning entity objects before you execute the search query.
Another alternative consists in calling refresh on each interested entity object.

But at first I personally would look, if the bulk update is really necessary at this point.
In most cases normal updates are the most natural way to work with hiberante and preferable to bulk updates.


Top
 Profile  
 
 Post subject: Re: hibernate hql ERROR: Not supported for DML operations
PostPosted: Fri Sep 28, 2012 8:02 am 
Newbie

Joined: Fri Sep 21, 2012 12:13 am
Posts: 7
i think i am doing normal updates thru the method calls not bulk. but my problem is still in DB update. The DB doesn't get updated even though i don't have any error at this point. I tried running this query directly in oracle which works fine. i changed the DAO method to void.

Code:
update WG_ROSTER set grade='B-', modify_flag='U', grade_date=to_date('2012-09-27', 'yyyy-MM-dd'), user_id='0:0:0:0:0:0:0:1'
where stubun='jj11112' and crs_cd='0073' and modify_flag<>'N'


Top
 Profile  
 
 Post subject: Re: hibernate hql ERROR: Not supported for DML operations
PostPosted: Fri Sep 28, 2012 11:05 am 
Newbie

Joined: Fri Sep 21, 2012 12:13 am
Posts: 7
Here is the console print. Sorry for the long log. I am trying to understand where i am making mistake. There is no exception or ERROR at this time but no Oracle DB update either.
You may notice two updates here since I am updating a student roster grade table.
I am calling a void DAO method with parameters in the controller for the UPDATE. The method rosterDAO.rosterGrdUpdate(p1,p2,p3,p4) is called in the controller method ModelAndView update_roster1_post(request,status)
You may also notice in the query below that i am using compound key: wr.compoundKey.stubun= :stb and wr.compoundKey.crs_cd= :cr

Code:
WGController---update_roster1_post**Ln545**stuGrdcnt : 2

0 --@@@  WGController---update_roster1_post**Ln581**stuBun :stuBun0  @@@@  jc11113
WGController---update_roster1_post**Ln609**
WgRosterDAO**Ln178**strDate    = 2012-09-30
WgRosterDAO**Ln241**UPDATE  stuGrdValue:A- modifyFlagUpdate:U todayStr:2012-09-30 pcID:0:0:0:0:0:0:0:1
WgRosterDAO**Ln250**querySt:QueryImpl(update  WgRoster wr set wr.grade= :gr, wr.modify_flag= :mf, wr.grade_date=to_date(:gd,'yyyy-MM-dd') , wr.user_id= :ud where wr.compoundKey.stubun= :stb and wr.compoundKey.crs_cd= :cr and wr.modify_flag !=  :mfu)
WgRosterDAO**Ln308**querySt:QueryImpl(update  WgRoster wr set wr.grade= :gr, wr.modify_flag= :mf, wr.grade_date=to_date(:gd,'yyyy-MM-dd') , wr.user_id= :ud where wr.compoundKey.stubun= :stb and wr.compoundKey.crs_cd= :cr and wr.modify_flag !=  :mfu)
WgRosterDAO**Ln309**UPDATE  stuGrdValue:A- modifyFlagUpdate:U todayStr:2012-09-30 pcID:0:0:0:0:0:0:0:1
WgRosterDAO**Ln310**WHERE  stuBunValue:jc11113 crsCd:0135 modifyFlagWh:N
WgRosterDAO**Ln312**Command successfully executed....
WgRosterDAO**Ln313**Number of records effected due to update query: 0
WgRosterDAO**Ln327*************BACK TO CONTROLLER ********************
WGController---update_roster1_post****Ln614**stuGradesInfo :stuBun0:jc11113;stuGrd0:A-;***

1 --@@@  WGController---update_roster1_post**Ln581**stuBun :stuBun1  @@@@  jj11112
WGController---update_roster1_post**Ln609**
WgRosterDAO**Ln178**strDate    = 2012-09-30
WgRosterDAO**Ln241**UPDATE  stuGrdValue:A- modifyFlagUpdate:U todayStr:2012-09-30 pcID:0:0:0:0:0:0:0:1
WgRosterDAO**Ln250**querySt:QueryImpl(update  WgRoster wr set wr.grade= :gr, wr.modify_flag= :mf, wr.grade_date=to_date(:gd,'yyyy-MM-dd') , wr.user_id= :ud where wr.compoundKey.stubun= :stb and wr.compoundKey.crs_cd= :cr and wr.modify_flag !=  :mfu)
WgRosterDAO**Ln308**querySt:QueryImpl(update  WgRoster wr set wr.grade= :gr, wr.modify_flag= :mf, wr.grade_date=to_date(:gd,'yyyy-MM-dd') , wr.user_id= :ud where wr.compoundKey.stubun= :stb and wr.compoundKey.crs_cd= :cr and wr.modify_flag !=  :mfu)
WgRosterDAO**Ln309**UPDATE  stuGrdValue:A- modifyFlagUpdate:U todayStr:2012-09-30 pcID:0:0:0:0:0:0:0:1
WgRosterDAO**Ln310**WHERE  stuBunValue:jj11112 crsCd:0135 modifyFlagWh:N
WgRosterDAO**Ln312**Command successfully executed....
WgRosterDAO**Ln313**Number of records effected due to update query: 0
WgRosterDAO**Ln327*************BACK TO CONTROLLER ********************
WGController---update_roster1_post****Ln614**stuGradesInfo :stuBun1:jj11112;stuGrd1:A-;***

WGController---update_roster1_post**Ln693**@@@@@@@@@@@@@@@@@@@@ TRANSFER TO JSP update_roster1-jsp @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
update_roster1-jsp**Ln144**sectionInfo:webgrade.spring.domain.WGSection@1406868[crs_cd=0135,div_cd=G,discipln_cd=14,crs_num=9800,sec_num=S2DA,crse_descr=INTENSIVE SURVEY LAW,password=abc123,init_psw_flag=N,send_to_registrar=N,send_date=<null>,confirm_number=<null>,send_to_sims=<null>,dept_cd=LAW,alt_dept_cd=<null>,alt_dept1_cd=<null>,alt_dept2_cd=<null>,paper_roster=N,credits=4,login_count=0,login_time=1990-01-01 00:00:00.0,signature=<null>,emailed=false]
update_roster1-jsp**Ln182**crsCd*:0135
update_roster1-jsp**Ln183**Sun Sep 30 01:09:12 EDT 2012  %%%%%%%%%%% END of iteration %%%%%%%%%%


Thanks for looking into this.


Top
 Profile  
 
 Post subject: Re: hibernate hql ERROR: Not supported for DML operations
PostPosted: Sun Sep 30, 2012 7:37 pm 
Newbie

Joined: Fri Sep 21, 2012 12:13 am
Posts: 7
I am able to resolve the update issue. the problem was inconsistency with the DB. I didn't have composite key to begin with in hibernate.
thanks again to pb00067 for giving tips.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.