LocalDateTime is not mapped correctly [message #1807600] |
Tue, 04 June 2019 13:07 |
Jeno Tobak Messages: 2 Registered: June 2017 |
Junior Member |
|
|
public class MyEntity {
@Id
Long id;
String name;
LocalDateTime date;
...
}
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<MyEntity> cq = cb.createQuery(MyEntity.class);
Root<MyEntity> root = cq.from(MyEntity.class);
cq.where(cb.and(cb.isTrue(cb.literal(Boolean.TRUE)), cb.lessThan(root.get("date"), LocalDateTime.now().plus(1l, ChronoUnit.DAYS))));
List<MyEntity> results = em.createQuery(cq).getResultList();
throws
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.4.v20190115-ad5b7c6b2a): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "SELECT ID, DATE, NAME FROM MYENTITY WHERE ((1 = 1) AND (DATE < 2019-06-05T14[*]:53:19.153))"; expected "[, ::, *, /, %, +, -, ||, ~, !~, NOT, LIKE, ILIKE, REGEXP, IS, IN, BETWEEN, AND, OR, ,, )"; SQL statement:
SELECT ID, DATE, NAME FROM MYENTITY WHERE ((1 = 1) AND (DATE < 2019-06-05T14:53:19.153)) [42001-199]
Error Code: 42001
Tested with H2 and DB2 databases.
Hibernate works well.
cq.where(cb.lessThan(root.get("date"), LocalDateTime.now().plus(1l, ChronoUnit.DAYS)));
or
cq.where(cb.isTrue(cb.literal(Boolean.TRUE)));
works too
|
|
|
|
Powered by
FUDForum. Page generated in 0.04115 seconds