2019-03-01 16:38:44.930警告55052 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper:SQL错误:932,SQLState: 42000
2019-03-01 16:38:44.930错误55052 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper:ORA-00932:不一致 数据类型:预期DATE得到NUMBER
2019-03-01 16:38:44.946错误55052 --- [nio-8080-exec-1] o.a.c.c.C。[。[。[/]。[dispatcherServlet]:的Servlet.service() 路径[]中的servlet [dispatcherServlet]抛出异常 [请求处理失败;嵌套异常为 org.springframework.dao.InvalidDataAccessResourceUsageException:可以 不提取ResultSet; SQL [n / a];嵌套异常为 org.hibernate.exception.SQLGrammarException:无法提取 ResultSet]的根本原因
oracle.jdbc.OracleDatabaseException:ORA-00932:不一致 数据类型:预期DATE得到NUMBER
我最终想要的查询,我猜只是使用spring CrudRepository格式不正确:
select * from user_usage where Prs_Id=1104438622 and createddate > sysdate -1;
desc user_usage
Name Null Type
------------- -------- --------------
USAGETYPEID NOT NULL NUMBER(3)
PRS_ID NOT NULL NUMBER(18)
CREATEDID NOT NULL NUMBER(10)
CREATEDDATE NOT NULL DATE
COMMENTS VARCHAR2(4000)
USERAGENTID NUMBER(10)
1)POJO
@Entity
@Table(name="USER_USAGE)
public class Usage {
@Column(name="Prs_Id")
@Id
private long prsId;
@Column(name="createddate")
private Date createddate;
2)存储库
public interface UsageRepository extends CrudRepository<Usage, Date>{
//select * from user_usage where Prs_Id=1104438622 and createddate > sysdate -1; --query that I want eventually
@Query("SELECT a FROM Usage a WHERE a.prsId=:prsId and a.createddate>=:createddate-1")
Usage fetchUsageGreaterThanEqual(@Param("prsId") Long prsId, @Param("createddate") Date createddate);
}
3)控制器:
@Autowired
UsageRepository usageRepository;
static Date myDate;
@GetMapping("/{prsId}")
public Usage getUsageByPrsId(@PathVariable Long prsId) {
return usageRepository.fetchUsageGreaterThanEqual(prsId, myDate);
}