首页 > 解决方案 > 提取日期时出现休眠查询错误

问题描述

请参阅错误日志后的更新


我在 spring 应用程序中有这样的代码:

@Query("SELECT e.status FROM EquipmentContract e")
List<String> getTerminationDates(); 

它有效。但是如果我更改查询,添加datetime类型的字段

@Query("SELECT e.status, e.terminated_date FROM EquipmentContract e")

它没有,向我暴露了这样的错误日志:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfiguration' defined in file [C:\Users\sergei.klevtsov\Documents\Projects\Work\ntt-inventory\target\classes\com\acn\inventory\config\SecurityConfiguration.class]: Unsatisfied dependency expressed through constructor parameter 5; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.zalando.problem.spring.web.advice.security.SecurityProblemSupport': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'handlerExceptionResolver' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerExceptionResolver]: Factory method 'handlerExceptionResolver' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.format.support.FormattingConversionService]: Factory method 'mvcConversionService' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'equipmentContractRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List com.acn.inventory.repository.EquipmentContractRepository.getTerminationDates()!

查询中是否应该使用一些额外的结构来处理datatime或......?


经过一些更改后,编译时的错误消失了,但现在在加载 REST 源代码后它说:

{
  "type" : "http://www.jhipster.tech/problem/problem-with-message",
  "title" : "Internal Server Error",
  "status" : 500,
  "detail" : "Could not write JSON: java.sql.Timestamp cannot be cast to [Ljava.lang.Object;; nested exception is com.fasterxml.jackson.databind.JsonMappingException: java.sql.Timestamp cannot be cast to [Ljava.lang.Object; (through reference chain: java.util.ArrayList[0])",
  "path" : "/api/equipment-contracts/terminations/dates",
  "message" : "error.http.500"
}

在我看来,解决方案就在附近(?)

标签: javaspringhibernatedatetimejhipster

解决方案


推荐阅读