Hi,
I'm trying to do an Update with Hibernate an here is the query : UPDATE Rejet r SET r.etatRejet=:etat , dateMaj=sysdate where noRejet=:noRejet
Here is my configuration:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> <context:annotation-config /> <context:component-scan base-package="fr.cnp.btd,fr.cnp.ods,fr.cnp.erc,erc.query"" />
<!-- ******************** DataSource BTD ************************ --> <bean id="dataSource_btd" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="BTD-IHM"/> <!-- Pour Tomcat --> <property name="resourceRef" value="true"/> </bean>
<bean id="entityManagerFactory_btd" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="packagesToScan" value="fr.cnp.btd.domaine.*"/> <property name="persistenceUnitName" value="db_btd"></property> <property name="jpaPropertyMap"> <map> <entry key="hibernate.dialect" value="${hibernate.dialect}"/> <entry key="hibernate.query.factory_class" value="org.hibernate.hql.classic.ClassicQueryTranslatorFactory"/> <entry key="hibernate.hbm2ddl.auto" value="validate"/> <!-- A utiliser pour faciliter le débogage --> <entry key="hibernate.show_sql" value="${hibernate.show_sql}"/> <entry key="hibernate.format_sql" value="${hibernate.format_sql}"/> </map> </property> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/> </property> <property name="dataSource" ref="dataSource_btd"/> </bean>
<!-- bean post-processor for JPA annotations --> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="transactionManager_btd" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory_btd"/> </bean> <tx:annotation-driven transaction-manager="transactionManager_btd"/> </beans>
Then I had the following error: org.hibernate.QueryException: query must begin with SELECT or FROM: update ....
I was advice to replace
<entry key="hibernate.query.factory_class" value="org.hibernate.hql.classic.ClassicQueryTranslatorFactory"/>
By
<entry key="hibernate.query.factory_class" value="org.hibernate.hql.ast.ASTQueryTranslatorFactory"/>
I have antlrXX.jar in my classpath.
Here is the new Error I'm having:
4:52:17,211 DEBUG RejetsController:170 - 13960435 14:52:19,479 DEBUG SharedEntityManagerCreator$SharedEntityManagerInvocationHandler:231 - Creating new EntityManager for shared EntityManager invocation 14:52:19,479 DEBUG SessionImpl:265 - opened session at timestamp: 14261683394 14:52:19,484 DEBUG QueryTranslatorImpl:274 - parse() - HQL: UPDATE fr.cnp.btd.domaine.btd.Rejet r SET r.etatRejet=:etat , dateMaj=sysdate where noRejet=:noRejet 14:52:19,496 DEBUG AST:293 - --- HQL AST --- \-[UPDATE] Node: 'UPDATE' +-[FROM] Node: 'FROM' | \-[RANGE] Node: 'RANGE' | +-[DOT] Node: '.' | | +-[DOT] Node: '.' | | | +-[DOT] Node: '.' | | | | +-[DOT] Node: '.' | | | | | +-[DOT] Node: '.' | | | | | | +-[IDENT] Node: 'fr' | | | | | | \-[IDENT] Node: 'cnp' | | | | | \-[IDENT] Node: 'btd' | | | | \-[IDENT] Node: 'domaine' | | | \-[IDENT] Node: 'btd' | | \-[IDENT] Node: 'Rejet' | \-[ALIAS] Node: 'r' +-[SET] Node: 'SET' | +-[EQ] Node: '=' | | +-[DOT] Node: '.' | | | +-[IDENT] Node: 'r' | | | \-[IDENT] Node: 'etatRejet' | | \-[COLON] Node: ':' | | \-[IDENT] Node: 'etat' | \-[EQ] Node: '=' | +-[IDENT] Node: 'dateMaj' | \-[IDENT] Node: 'sysdate' \-[WHERE] Node: 'where' \-[EQ] Node: '=' +-[IDENT] Node: 'noRejet' \-[COLON] Node: ':' \-[IDENT] Node: 'noRejet'
14:52:19,497 DEBUG ErrorCounter:91 - throwQueryException() : no errors 14:52:19,500 DEBUG HqlSqlBaseWalker:111 - update << begin [level=1, statement=update] 14:52:19,501 DEBUG FromElement:157 - FromClause{level=1} : fr.cnp.btd.domaine.btd.Rejet (r) -> rejet0_ 14:52:19,501 DEBUG FromReferenceNode:74 - Resolved : r -> NO_REJET 14:52:19,502 DEBUG DotNode:613 - getDataType() : etatRejet -> org.hibernate.type.StringType@12d34a6 14:52:19,503 DEBUG FromReferenceNode:74 - Resolved : r.etatRejet -> ETAT_REJET 14:52:19,504 DEBUG FromReferenceNode:74 - Resolved : {synthetic-alias} -> {synthetic-alias} 14:52:19,504 DEBUG DotNode:613 - getDataType() : dateMaj -> org.hibernate.type.TimestampType@1dcc3ca 14:52:19,504 DEBUG FromReferenceNode:74 - Resolved : {synthetic-alias}.dateMaj -> DATE_MAJ 14:52:19,511 DEBUG FromReferenceNode:74 - Resolved : {synthetic-alias} -> {synthetic-alias} 14:52:19,512 DEBUG DotNode:613 - getDataType() : noRejet -> org.hibernate.type.LongType@71a97 14:52:19,512 DEBUG FromReferenceNode:74 - Resolved : {synthetic-alias}.noRejet -> NO_REJET 14:52:19,513 DEBUG HqlSqlBaseWalker:117 - update : finishing up [level=1, statement=update] 14:52:19,513 DEBUG HqlSqlBaseWalker:123 - update >> end [level=1, statement=update] 14:52:19,517 DEBUG AST:260 - --- SQL AST --- \-[UPDATE] UpdateStatement: 'UPDATE' querySpaces (ABTDDEVX.TDO_BTD_REJET) +-[FROM] FromClause: 'FROM' FromClause{level=1, fromElementCounter=1, fromElements=1, fromElementByClassAlias=[r], fromElementByTableAlias=[rejet0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]} | \-[FROM_FRAGMENT] FromElement: 'ABTDDEVX.TDO_BTD_REJET' FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=r,role=null,tableName=ABTDDEVX.TDO_BTD_REJET,tableAlias=rejet0_,origin=null,columns={,className=fr.cnp.btd.domaine.btd.Rejet}} +-[SET] SqlNode: 'SET' | +-[EQ] BinaryLogicOperatorNode: '=' | | +-[DOT] DotNode: 'ETAT_REJET' {propertyName=etatRejet,dereferenceType=ALL,propertyPath=etatRejet,path=r.etatRejet,tableAlias=rejet0_,className=fr.cnp.btd.domaine.btd.Rejet,classAlias=r} | | | +-[ALIAS_REF] IdentNode: 'NO_REJET' {alias=r, className=fr.cnp.btd.domaine.btd.Rejet, tableAlias=rejet0_} | | | \-[IDENT] IdentNode: 'etatRejet' {originalText=etatRejet} | | \-[NAMED_PARAM] ParameterNode: '?' {name=etat, expectedType=org.hibernate.type.StringType@12d34a6} | \-[EQ] BinaryLogicOperatorNode: '=' | +-[DOT] DotNode: 'DATE_MAJ' {propertyName=dateMaj,dereferenceType=ALL,propertyPath=dateMaj,path={synthetic-alias}.dateMaj,tableAlias=rejet0_,className=fr.cnp.btd.domaine.btd.Rejet,classAlias=r} | | +-[IDENT] IdentNode: '{synthetic-alias}' {originalText={synthetic-alias}} | | \-[IDENT] IdentNode: 'dateMaj' {originalText=dateMaj} | \-[IDENT] IdentNode: 'sysdate' {originalText=sysdate} \-[WHERE] SqlNode: 'where' \-[EQ] BinaryLogicOperatorNode: '=' +-[DOT] DotNode: 'NO_REJET' {propertyName=noRejet,dereferenceType=ALL,propertyPath=noRejet,path={synthetic-alias}.noRejet,tableAlias=rejet0_,className=fr.cnp.btd.domaine.btd.Rejet,classAlias=r} | +-[IDENT] IdentNode: '{synthetic-alias}' {originalText={synthetic-alias}} | \-[IDENT] IdentNode: 'noRejet' {originalText=noRejet} \-[NAMED_PARAM] ParameterNode: '?' {name=noRejet, expectedType=org.hibernate.type.LongType@71a97}
14:52:19,519 DEBUG ErrorCounter:91 - throwQueryException() : no errors 14:52:19,530 DEBUG ErrorCounter:91 - throwQueryException() : no errors 14:52:19,531 DEBUG EntityManagerFactoryUtils:343 - Closing JPA EntityManager 14:52:33,749 DEBUG ExceptionHandlerExceptionResolver:132 - Resolving exception from handler [public java.lang.String fr.cnp.btd.web.controller.RejetsController.modifierEtatRejets(java.lang.Long[],java.lang.String,java.lang.String,fr.cnp.btd.web.form.ListeRejetsForm)]: java.lang.NullPointerException 14:52:33,874 DEBUG ResponseStatusExceptionResolver:132 - Resolving exception from handler [public java.lang.String fr.cnp.btd.web.controller.RejetsController.modifierEtatRejets(java.lang.Long[],java.lang.String,java.lang.String,fr.cnp.btd.web.form.ListeRejetsForm)]: java.lang.NullPointerException 14:52:33,874 DEBUG DefaultHandlerExceptionResolver:132 - Resolving exception from handler [public java.lang.String fr.cnp.btd.web.controller.RejetsController.modifierEtatRejets(java.lang.Long[],java.lang.String,java.lang.String,fr.cnp.btd.web.form.ListeRejetsForm)]: java.lang.NullPointerException 14:52:33,874 DEBUG DispatcherServlet:910 - Could not complete request java.lang.NullPointerException at org.hibernate.hql.ast.QueryTranslatorImpl.getDynamicInstantiationResultType(QueryTranslatorImpl.java:580) at org.hibernate.engine.query.HQLQueryPlan.getDynamicInstantiationResultType(HQLQueryPlan.java:341) at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:304) 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.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365) at $Proxy26.createQuery(Unknown Source) 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.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240) at $Proxy26.createQuery(Unknown Source) at fr.cnp.btd.dao.btd.RejetDAO.majEtatRejet(RejetDAO.java:142) at fr.cnp.btd.service.metier.RejetMetier.majEtatRejet(RejetMetier.java:114) at fr.cnp.btd.web.controller.RejetsController.modifierEtatRejets(RejetsController.java:173) 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.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789) at javax.servlet.http.HttpServlet.service(HttpServlet.java:646) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source) 12 mars 2015 14:52:33 org.apache.catalina.core.StandardWrapperValve invoke GRAVE: Servlet.service() for servlet [dispatcher] in context with path [/web] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause java.lang.NullPointerException at org.hibernate.hql.ast.QueryTranslatorImpl.getDynamicInstantiationResultType(QueryTranslatorImpl.java:580) at org.hibernate.engine.query.HQLQueryPlan.getDynamicInstantiationResultType(HQLQueryPlan.java:341) at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:304) 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.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365) at $Proxy26.createQuery(Unknown Source) 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.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240) at $Proxy26.createQuery(Unknown Source) at fr.cnp.btd.dao.btd.RejetDAO.majEtatRejet(RejetDAO.java:142) at fr.cnp.btd.service.metier.RejetMetier.majEtatRejet(RejetMetier.java:114) at fr.cnp.btd.web.controller.RejetsController.modifierEtatRejets(RejetsController.java:173) 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.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789) at javax.servlet.http.HttpServlet.service(HttpServlet.java:646) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source)
Please, Help.
Regards
|