【发布时间】:2017-12-30 19:39:27
【问题描述】:
我正在根据两列日期和时间查询表以返回行:tx_creation_date [date] 和 tx_creation_time [time(7)]
使用以下查询语句:
public interface PurchaseRepository extends PagingAndSortingRepository<Purchase, BigDecimal> {
@Query(value = "select p from Purchase p where (p.txCreationDate >=
:startDate and p.txCreationTime >= :startTime) and (p.txCreationDate <= :endDate and p.txCreationTime <= :endTime)")
public List<Purchase> findAllTxByTimestampRange(@Param(startDate) LocalDate startDate,
@Param(startTime) LocalTime startTime, @Param(endDate) LocaleDate endDate,
@Param(endTime) LocalTime endTime);
other queries...
}
这里是 Purchase 类的一个 sn-p:
@Entity
@Table(name = "po_log")
public class Purchase implements Serializable {
private static final long serialVersionUID = -1L;
@Id
@Column(name = "po_number")
private BigDecimal poNumber;
private String type;
@Column(name = "tx_creation_date")
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
private LocalDate txCreationDate;
@Column(name = "tx_creation_time")
@Type(type = "org.jadira.usertype.dateandtime.joda.PersitentLocalTime")
private LocalTime txCreationTime;
..
..
getters and setters
}
执行时我收到以下错误消息:
数据类型datetime和time在大于等于运算符中不兼容
我尝试了几个技巧都没有成功:
- 在连接属性中设置此
sendTimeAsDateTime=false - 使用
cast (txCreationTime as time)或convert - 使用
cast将日期和时间连接为datetime
非常感谢任何帮助。
旁注:选择具有日期范围的行只会成功。因此,问题真正在于时间。
我目前的设置:
- 弹簧注解
- 休眠 4
- Jadira 用于用户类型,Joda 用于 LocalDate 和 LocalTime
- SQL Server 2014
- localDate 从用户格式化为 yyyyMMdd
- 从用户格式化为 HHmmssSSS 的本地时间
【问题讨论】:
标签: sql-server spring hibernate jpa jodatime