Query query = session.createQuery("from Employee e where e.joiningDate > :date"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); LocalDateTime dateTime = LocalDateTime.parse("2021-01-01 00:00:00", formatter); query.setTimestamp("date", Timestamp.valueOf(dateTime)); Listemployees = query.list();
Query query = session.createQuery("from Order o where o.datePlaced < :date"); Date date = new Date(); query.setTimestamp("date", new Timestamp(date.getTime())); ListIn this example, we are querying for all orders that were placed before the current date and time. We are using the setTimestamp method to set a date parameter to the current date and time. The package library for org.hibernate Query setTimestamp is Hibernate ORM.orders = query.list();