hibernate - How to execute Native SQL server query without resultset using Spring Data JPA -
i using spring data jpa , hibernate create repository in which, among other things, have added 2 queries enable or disable insert identity can add values specified id. thought correct create native query in interface
public interface partrepo extends pagingandsortingrepository <part,long > { //other methods @query(value = "set identity_insert part on", nativequery = true) public void enableinsertidentity(); @query(value = "set identity_insert part off", nativequery = true) public void disableinsertidentity(); }
but when hibernate executes 1 of set identity_insert
queries receive error:
com.microsoft.sqlserver.jdbc.sqlserverexception: statement did not return result set.
this full stacktrace:
hibernate: set identity_insert part on 2016-02-08 15:20:06.069 warn 7580 --- [nio-8081-exec-1] o.h.engine.jdbc.spi.sqlexceptionhelper : sql error: 0, sqlstate: null 2016-02-08 15:20:06.069 error 7580 --- [nio-8081-exec-1] o.h.engine.jdbc.spi.sqlexceptionhelper : statement did not return result set. 2016-02-08 15:20:06.527 error 7580 --- [nio-8081-exec-1] o.a.c.c.c.[.[.[/].[dispatcherservlet] : servlet.service() servlet [dispatcherservlet] in context path [] threw exception [request processing failed; nested exception javax.persistence.persistenceexception: org.hibernate.exception.genericjdbcexception: not extract resultset] root cause com.microsoft.sqlserver.jdbc.sqlserverexception: statement did not return result set. @ com.microsoft.sqlserver.jdbc.sqlserverexception.makefromdrivererror(sqlserverexception.java:191) @ com.microsoft.sqlserver.jdbc.sqlserverpreparedstatement.doexecutepreparedstatement(sqlserverpreparedstatement.java:450) @ com.microsoft.sqlserver.jdbc.sqlserverpreparedstatement$prepstmtexeccmd.doexecute(sqlserverpreparedstatement.java:383) @ com.microsoft.sqlserver.jdbc.tdscommand.execute(iobuffer.java:6703) @ com.microsoft.sqlserver.jdbc.sqlserverconnection.executecommand(sqlserverconnection.java:1929) @ com.microsoft.sqlserver.jdbc.sqlserverstatement.executecommand(sqlserverstatement.java:184) @ com.microsoft.sqlserver.jdbc.sqlserverstatement.executestatement(sqlserverstatement.java:159) @ com.microsoft.sqlserver.jdbc.sqlserverpreparedstatement.executequery(sqlserverpreparedstatement.java:295) @ org.hibernate.engine.jdbc.internal.resultsetreturnimpl.extract(resultsetreturnimpl.java:82) @ org.hibernate.loader.loader.getresultset(loader.java:2066) @ org.hibernate.loader.loader.executequerystatement(loader.java:1863) @ org.hibernate.loader.loader.executequerystatement(loader.java:1839) @ org.hibernate.loader.loader.doquery(loader.java:910) @ org.hibernate.loader.loader.doqueryandinitializenonlazycollections(loader.java:355) @ org.hibernate.loader.loader.dolist(loader.java:2554) @ org.hibernate.loader.loader.dolist(loader.java:2540) @ org.hibernate.loader.loader.listignorequerycache(loader.java:2370) @ org.hibernate.loader.loader.list(loader.java:2365) @ org.hibernate.loader.custom.customloader.list(customloader.java:353) @ org.hibernate.internal.sessionimpl.listcustomquery(sessionimpl.java:1909) @ org.hibernate.internal.abstractsessionimpl.list(abstractsessionimpl.java:311) @ org.hibernate.internal.sqlqueryimpl.list(sqlqueryimpl.java:141) @ org.hibernate.jpa.internal.queryimpl.list(queryimpl.java:573) @ org.hibernate.jpa.internal.queryimpl.getsingleresult(queryimpl.java:495) @ org.springframework.data.jpa.repository.query.jpaqueryexecution$singleentityexecution.doexecute(jpaqueryexecution.java:202) @ org.springframework.data.jpa.repository.query.jpaqueryexecution.execute(jpaqueryexecution.java:74) @ org.springframework.data.jpa.repository.query.abstractjpaquery.doexecute(abstractjpaquery.java:97) @ org.springframework.data.jpa.repository.query.abstractjpaquery.execute(abstractjpaquery.java:88) @ org.springframework.data.repository.core.support.repositoryfactorysupport$queryexecutormethodinterceptor.doinvoke(repositoryfactorysupport.java:395) @ org.springframework.data.repository.core.support.repositoryfactorysupport$queryexecutormethodinterceptor.invoke(repositoryfactorysupport.java:373) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.data.repository.core.support.repositoryfactorysupport$defaultmethodinvokingmethodinterceptor.invoke(repositoryfactorysupport.java:486) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.transaction.interceptor.transactioninterceptor$1.proceedwithinvocation(transactioninterceptor.java:99) @ org.springframework.transaction.interceptor.transactionaspectsupport.invokewithintransaction(transactionaspectsupport.java:281) @ org.springframework.transaction.interceptor.transactioninterceptor.invoke(transactioninterceptor.java:96) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.dao.support.persistenceexceptiontranslationinterceptor.invoke(persistenceexceptiontranslationinterceptor.java:136) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.data.jpa.repository.support.crudmethodmetadatapostprocessor$crudmethodmetadatapopulatingmethodintercceptor.invoke(crudmethodmetadatapostprocessor.java:122) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.aop.interceptor.exposeinvocationinterceptor.invoke(exposeinvocationinterceptor.java:92) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:207) @ com.sun.proxy.$proxy126.enableinsertidentity(unknown source) @ it.cdc.snp.business.supply.feedingbusinessanag.feedallparts(feedingbusinessanag.java:40) @ it.cdc.snp.business.supply.feedingbusinessanag$$fastclassbyspringcglib$$beb28ba9.invoke(<generated>) @ org.springframework.cglib.proxy.methodproxy.invoke(methodproxy.java:204) @ org.springframework.aop.framework.cglibaopproxy$cglibmethodinvocation.invokejoinpoint(cglibaopproxy.java:717) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:157) @ org.springframework.cloud.context.config.standardbeanlifecycledecorator$2.invoke(standardbeanlifecycledecorator.java:85) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.aop.framework.cglibaopproxy$dynamicadvisedinterceptor.intercept(cglibaopproxy.java:653) @ it.cdc.snp.business.supply.feedingbusinessanag$$enhancerbyspringcglib$$aaf07810.feedallparts(<generated>) @ it.cdc.snp.business.supply.feedingbusinessanag$$fastclassbyspringcglib$$beb28ba9.invoke(<generated>) @ org.springframework.cglib.proxy.methodproxy.invoke(methodproxy.java:204) @ org.springframework.aop.framework.cglibaopproxy$cglibmethodinvocation.invokejoinpoint(cglibaopproxy.java:717) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:157) @ org.springframework.aop.support.delegatingintroductioninterceptor.doproceed(delegatingintroductioninterceptor.java:133) @ org.springframework.aop.support.delegatingintroductioninterceptor.invoke(delegatingintroductioninterceptor.java:121) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.aop.framework.cglibaopproxy$dynamicadvisedinterceptor.intercept(cglibaopproxy.java:653) @ it.cdc.snp.business.supply.feedingbusinessanag$$enhancerbyspringcglib$$5dc38301.feedallparts(<generated>) @ it.cdc.snp.services.rest.genericrestapi.saveanag(genericrestapi.java:70) @ it.cdc.snp.services.rest.genericrestapi$$fastclassbyspringcglib$$398e7cc1.invoke(<generated>) @ org.springframework.cglib.proxy.methodproxy.invoke(methodproxy.java:204) @ org.springframework.aop.framework.cglibaopproxy$cglibmethodinvocation.invokejoinpoint(cglibaopproxy.java:717) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:157) @ org.springframework.cloud.context.config.standardbeanlifecycledecorator$2.invoke(standardbeanlifecycledecorator.java:85) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.aop.framework.cglibaopproxy$dynamicadvisedinterceptor.intercept(cglibaopproxy.java:653) @ it.cdc.snp.services.rest.genericrestapi$$enhancerbyspringcglib$$a51a0728.saveanag(<generated>) @ it.cdc.snp.services.rest.genericrestapi$$fastclassbyspringcglib$$398e7cc1.invoke(<generated>) @ org.springframework.cglib.proxy.methodproxy.invoke(methodproxy.java:204) @ org.springframework.aop.framework.cglibaopproxy$cglibmethodinvocation.invokejoinpoint(cglibaopproxy.java:717) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:157) @ org.springframework.aop.support.delegatingintroductioninterceptor.doproceed(delegatingintroductioninterceptor.java:133) @ org.springframework.aop.support.delegatingintroductioninterceptor.invoke(delegatingintroductioninterceptor.java:121) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.aop.framework.cglibaopproxy$dynamicadvisedinterceptor.intercept(cglibaopproxy.java:653) @ it.cdc.snp.services.rest.genericrestapi$$enhancerbyspringcglib$$b5080d19.saveanag(<generated>) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ org.springframework.web.method.support.invocablehandlermethod.doinvoke(invocablehandlermethod.java:221) @ org.springframework.web.method.support.invocablehandlermethod.invokeforrequest(invocablehandlermethod.java:137) @ org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:110) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlemethod(requestmappinghandleradapter.java:776) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:705) @ org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:85) @ org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:959) @ org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:893) @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:966) @ org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:857) @ javax.servlet.http.httpservlet.service(httpservlet.java:622) @ org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:842) @ javax.servlet.http.httpservlet.service(httpservlet.java:729) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:291) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.springframework.boot.actuate.autoconfigure.endpointwebmvcautoconfiguration$applicationcontextheaderfilter.dofilterinternal(endpointwebmvcautoconfiguration.java:295) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.springframework.boot.actuate.trace.webrequesttracefilter.dofilterinternal(webrequesttracefilter.java:102) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.springframework.web.filter.hiddenhttpmethodfilter.dofilterinternal(hiddenhttpmethodfilter.java:77) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.springframework.web.filter.characterencodingfilter.dofilterinternal(characterencodingfilter.java:85) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.springframework.boot.actuate.autoconfigure.metricsfilter.dofilterinternal(metricsfilter.java:68) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:219) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:106) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:502) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:142) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:79) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:88) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:518) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1091) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:668) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun(nioendpoint.java:1521) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.run(nioendpoint.java:1478) @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(unknown source)
and have no idea @ point, have tried searching on google found nothing
by default @query
considered select
query. make treated modifying query, use @modifying
annotation:
indicates method should regarded modifying query.
so, should write repository following way:
public interface partrepo extends pagingandsortingrepository<part,long> { @modifying @query(value = "set identity_insert part on", nativequery = true) public void enableinsertidentity(); @modifying @query(value = "set identity_insert part off", nativequery = true) public void disableinsertidentity(); }
Comments
Post a Comment