现在,我正在尝试通过使用查询更新实体来更改数据库中的某些数据,但出现此错误:
HTTP Status 500 - Request processing failed; nested exception is
org.springframework.orm.jpa.JpaSystemException: could not extract ResultSet; nested exception is
org.hibernate.exception.GenericJDBCException: could not extract ResultSet
这是我的Mapping Controller :
@RequestMapping(value="/vacChange", method = RequestMethod.POST)
public String changedVac(@RequestParam(value = "id", required = true) Integer id,
@RequestParam(value = "ort", required = true) String ort,
@RequestParam(value = "bereich", required = true) String bereich,
@RequestParam(value = "beschreibung", required = true) String beschreibung){
vacService.changeVacancyByID(id,gehalt,ort,bereich,beschreibung);
return "vacAdmin";
}
这是我使用的服务类方法:
void changeVacancyByID(Integer id, String gehalt,String ort,String bereich,String beschreibung);
}
服务方法的实现:
public void changeVacancyByID(Integer id, String gehalt,String ort,String bereich,String beschreibung){
System.out.println("Edit method called");
VacancyEntity vacEntity = vacancyRepository.findOneById(id);
vacancyRepository.updateAttributes(id,gehalt,ort,bereich,beschreibung);
}
好吧,这是我使用的查询:
@Transactional
@Query (value = "UPDATE vacancy SET salary=?2, location=?3,functionality=?4, description=?5 WHERE id = ?1 ", nativeQuery = true)
void updateAttributes(Integer id, String gehalt, String ort, String bereich, String beschreibung);
此外,还包括VacancyEntity类,getter和setter:
@Entity(name = "vacancy")
public class VacancyEntity {
@Id
@GeneratedValue
@Column(name = "id")
/**
* the vacancy identifier.
* "@Id": id is key attribute in database table vacancy.
* "@GenerartedValue": new inserted vacancies will get an id automatically.
* "@Column": name of colum in database table vacancy.
*/
private Integer id;
@Lob
@Column(name = "description")
/**
* The vacancy description, a full text.
*/
private String description;
@Column(name = "functionality")
/**
* The vacancy functionality.
*/
private String functionality;
@Column(name = "titel")
/**
* The vacancy titel.
*/
private String titel;
@Column(name = "salary")
/**
* The vacancy salary.
*/
private String salary;
@Column(name = "contracttype")
/**
* Type of Contract for the Vacancy. For further info go to "Mögliche Filter für Stellen und Bewerbungen.pdf" (section: Vertragsart) in the wiki"
*/
private String contractType;
@Column(name = "employmenttype")
/**
* Type of Employment. For further info go to "Mögliche Filter für Stellen und Bewerbungen.pdf" (section: Beschäftigungsverhältnis) in the wiki
*/
private String employmentType;
@Column(name = "interestgroup")
/**
* The vacancy's interest group. For further info go to "Mögliche Filter für Stellen und Bewerbungen.pdf" (section: Interessengruppe) in the wiki
*/
private String interestGroup;
@Column(name = "abstractdescription")
/**
* A brief description of the occupation.
* No Lob: please restrict the number of characters.
*/
private String abstractDescription;
@Column(name = "travel")
/**
*
*/
private String travel;
@Column(name = "requirements")
/**
* Requirements, the applicants have to fullfill.
*/
private String requirements;
@Column(name = "location")
/**
* The location of the vacancy. (Cities e.g. Bielefeld, Berlin, München...)
*/
private String location;
@Column(name = "commencement")
/**
* The date, at which the applicant can begin to work.
*/
private String commencement;
@Column(name = "duration")
/**
* The time period of employment.
*/
private String duration;
@Column(name = "tasks")
/**
* The tasks the applicant can expect.
*/
private String tasks;
@Column(name = "referencecode")
/**
* The reference Code.
*/
private String referenceCode;
@Column(name = "employmentlevel")
/**
* The level of employment (e.g. full time, part time...)
*/
private String employmentLevel;
@Column(name = "buisnesstravel")
/**
* Information as to the necessity of buisness trips.
*/
private String buisnessTravel;
public VacancyEntity() {
}
/**
* Constructor of class VacancyEntity.
* @param id, the given id
* @param titel, the given titel
* @param functionality, the given functionality
* @param salary, the given salary
* @param description , the given description
* @param contractType, the given type of contract
* @param employmentType, the given type of employment
* @param interestGroup, the given interest group
* @param abstractDescription, the given short version of the description
* @param requirements, the given requirements.
* @param location, the given location of the vacancy.
* @param commencement, the given date, at which the applicant can begin to work.
* @param duration, the given time period of employment.
* @param tasks, the given tasks.
* @param referenceCode, the given reference code.
* @param employmentLevel, the given level of employment.
* @param buisnessTravel, the given necessity of buisness trips.
*/
public VacancyEntity(Integer id,
String titel,
String functionality,
String salary,
String description,
String contractType,
String employmentType,
String interestGroup,
String abstractDescription,
String requirements,
String location,
String commencement,
String duration,
String tasks,
String referenceCode,
String employmentLevel,
String buisnessTravel)
{
this.id = id;
this.description = description;
this.functionality = functionality;
this.titel = titel;
this.salary = salary;
this.contractType = contractType;
this.employmentType = employmentType;
this.interestGroup = interestGroup;
this.abstractDescription = abstractDescription;
this.requirements = requirements;
this.location = location;
this.commencement = commencement;
this.duration = duration;
this.tasks = tasks;
this.referenceCode = referenceCode;
this.employmentLevel = employmentLevel;
this.buisnessTravel = buisnessTravel;
}
这是完整的堆栈跟踪:
Use execute or executeUpdate instead of executeQuery; SQL statement:
UPDATE vacancy SET salary=?, location=?,functionality=?, description=? WHERE id = ? [90002-185]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:179)
at org.h2.message.DbException.get(DbException.java:155)
at org.h2.message.DbException.get(DbException.java:144)
at org.h2.command.Prepared.query(Prepared.java:212)
at org.h2.command.CommandContainer.query(CommandContainer.java:90)
at org.h2.command.Command.executeQuery(Command.java:197)
at org.h2.jdbc.JdbcPreparedStatement.executeQuery(JdbcPreparedStatement.java:108)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:80)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2065)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1862)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838)
at org.hibernate.loader.Loader.doQuery(Loader.java:909)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)
at org.hibernate.loader.Loader.doList(Loader.java:2551)
at org.hibernate.loader.Loader.doList(Loader.java:2537)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2367)
at org.hibernate.loader.Loader.list(Loader.java:2362)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:353)
at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1869)
at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:311)
at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:141)
at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:573)
at org.hibernate.jpa.internal.QueryImpl.getSingleResult(QueryImpl.java:495)
at org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:142)
at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:61)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:96)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:86)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:337)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.LockModeRepositoryPostProcessor$LockModePopulatingMethodIntercceptor.invoke(LockModeRepositoryPostProcessor.java:105)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy97.updateAttributes(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy98.updateAttributes(Unknown Source)
at de.unibielefeld.techfak.tdpe.jsp.domain.VacancyServiceImpl.changeVacancyByID(VacancyServiceImpl.java:129)
at de.unibielefeld.techfak.tdpe.jsp.VacancyController.changedVac(VacancyController.java:234)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
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.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:146)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:125)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:105)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:57)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
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.valves.RemoteIpValve.invoke(RemoteIpValve.java:683)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
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.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1721)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1679)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
最佳答案
UPDATE
操作不会返回任何内容(您可以尝试在自己喜欢的数据库客户端中运行查询),因此,当尝试根据更新查询的结果构造VacancyEntity
时,spring失败。您还需要将@Modifying
添加到查询because it's an updating query中。
要解决此问题,请将您的存储库更改为此:
@Transactional
@Modifying
@Query (value = "UPDATE vacancy SET salary=?2, location=?3,functionality=?4, description=?5 WHERE id = ?1 ", nativeQuery = true)
void updateAttributes(Integer id, String gehalt, String ort, String bereich, String beschreibung);
关于java - 无法提取ResultSet,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30513975/