Spring Data:使用LocalDate参数

时间:2017-02-02 08:21:28

标签: hibernate spring-data

我正在使用带有注释的Spring Data 我想通过存储库调用带有参数(LocalDate)的本机命名查询 当我调用此查询时,我收到此错误:

o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 1271, SQLState: HY000
o.h.engine.jdbc.spi.SqlExceptionHelper   : Illegal mix of collations for operation '<'
c.g.r.event.EventBuilder$HostnameCache   : Updating the hostname cache
o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Warning Code: 1292, SQLState: 22007
o.h.engine.jdbc.spi.SqlExceptionHelper   : Incorrect date value: '��' for column 'entry_date' at row 1
o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Warning Code: 1271, SQLState: HY000
o.h.engine.jdbc.spi.SqlExceptionHelper   : Illegal mix of collations for operation '<'
c.t.myApp.aop.logging.LoggingAspect      : Exception in com.techvalley.tecfel.web.rest.PlanningResource.getPays() with cause = {} and exception {}
...
Caused by: java.sql.SQLException: Illegal mix of collations for operation '<'
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478)
    at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1274)
    at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:780)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1962)
    at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
    at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:82)
    ... 175 common frames omitted

这是我的代码,我在param中输入的日期是正确的(&#34; 2017-02-01&#34;)。 :

具有命名查询的实体:

@Entity
@Table(name = "stock")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@NamedNativeQuery(name = "Stock.getPlanningFromStock",
    query = "Select s.nom from stock where s.entry_date = :date1", resultSetMapping = "planningFromStockMapping" )

Spring MVC资源

@RequestMapping(value = "/stock-planning/{entryDate}",
        method = RequestMethod.GET,
        produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public List<PlanningDTO> getPlanning(@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate entryDate ) {


    List<PlanningDTO> plannings = stockRepository.getPlanningFromStock(entryDate);
    return null;
}

存储库:

List<PlanningDTO> getPlanningFromStock(@Param("date1") LocalDate date1);

0 个答案:

没有答案