Compare Date entities in JPA Criteria API

前端 未结 4 840
离开以前
离开以前 2020-12-03 00:20

Using JPA 2 with EclipseLink implementation.

I\'m trying to build a dynamic query which should bring me some records persisted after a given date.



        
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 01:00

    You need to use the generated metamodel to access the attributes is a really safe way. If you use Strings to refer to your attributes, types can only be deduced from the explicit generic type used when calling the method, or by a type cast, or by the automatic type inference done by the compiler:

    Path dateCreatedPath = root.get("dateCreated");
    predicates.add(builder.lessThanOrEqualTo(dateCreatedPath, dateLimit));
    

提交回复
热议问题