Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » LocalDateTime is not mapped correctly(LocalDateTime is not mapped correctly in criteriaquery with isTrue)
LocalDateTime is not mapped correctly [message #1807600] Tue, 04 June 2019 13:07
Jeno Tobak is currently offline Jeno TobakFriend
Messages: 1
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
Previous Topic:ValidationException
Next Topic:Synchronization error when insertable = false in EclipseLink
Goto Forum:
  


Current Time: Tue Oct 22 14:37:37 GMT 2019

Powered by FUDForum. Page generated in 0.01330 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top