给出:
@Entity
public class Paramter() {
@Id
private Long id;
private LocalDateTime startDate;
// getters & setters
}
// Extract from repository/dao method that grabs parameters:
...
final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
final CriteriaQuery<Parameter> query = builder.createQuery(Parameter.class);
final Root<Parameter> param = query.from(Parameter);
// The line below is generates following compilation error due to mismatch
// of the types of LocalDateTime and Timestamp parameters:
// java: no suitable method found for greaterThanOrEqualTo(javax.persistence.criteria.Path<java.time.LocalDateTime>,javax.persistence.criteria.Expression<java.sql.Timestamp>)
query.where(builder.greaterThanOrEqualTo(param.get(Parameter_.startDate), builder.currentTimestamp())); ...
如何通过jpa条件构建器正确使用java 8日期时间api(更具体地说是LocalDateTime属性)来实现:“从start_date> = sysdate的参数中选择*”? 请考虑:
使用似乎包含JPA 2.1的Hibernate 5.2.16。更改为JPA 2.2似乎没有什么不同。