Nor java.util.Date nor java.util.Calendar has microsecond precision, so forget using them as parameters!
Use java.sql.Timestamp, which has nanosecond precision. In this case be careful to set the nano field on the Timestamp
( java.sql.Timestamp way of storing NanoSeconds )
I created a simple scenario for testing:
CREATE TABLE precisetimes(id NUMBER(2), precisetime TIMESTAMP(6));
insert into precisetimes values(1, TO_TIMESTAMP('2017-05-31 12:12:12.123456','YYYY-MM-DD HH:MI:SS.FF'));
insert into precisetimes values(2, TO_TIMESTAMP('2017-05-31 12:12:12.12','YYYY-MM-DD HH:MI:SS.FF'));
insert into precisetimes values(3, TO_TIMESTAMP('2017-05-31 12:12:12.123457','YYYY-MM-DD HH:MI:SS.FF'));
commit;
select id,TO_CHAR(precisetime, 'YYYY-MM-DD HH:MI:SS.FF') ptime from precisetimes;
selecting all:
ID PTIME
---------- -----------------------------
1 2017-05-31 12:12:12.123456
2 2017-05-31 12:12:12.120000
3 2017-05-31 12:12:12.123457
After this preparation the following code:
TypedQuery<Precisetimes> q = entityManager.createQuery(
"select p from Precisetimes p where p.precisetime < :param",
Precisetimes.class);
Timestamp ts;
ts = Timestamp.valueOf("2017-05-31 12:12:12.123456");
q.setParameter("param", ts, TemporalType.TIMESTAMP);
System.out.println("result: " + q.getResultList());
ts = Timestamp.valueOf("2017-05-31 12:12:12.123457");
q.setParameter("param", ts, TemporalType.TIMESTAMP);
System.out.println("result: " + q.getResultList());
ts = Timestamp.valueOf("2017-05-31 12:12:12.123458");
q.setParameter("param", ts, TemporalType.TIMESTAMP);
System.out.println("result: " + q.getResultList());
has this result:
result: [id: 2, precisetime: 2017-05-31 12:12:12.12]
result: [id: 1, precisetime: 2017-05-31 12:12:12.123456, id: 2, precisetime: 2017-05-31 12:12:12.12]
result: [id: 1, precisetime: 2017-05-31 12:12:12.123456, id: 2, precisetime: 2017-05-31 12:12:12.12, id: 3, precisetime: 2017-05-31 12:12:12.123457]
I guess this is what you need? I uploaded the test example here: http://peter.risko.hu/java_incubator/jpa_hibernate_oracle_precisetimestamp.zip
Note that there's an other way round, converting the Oracle timestamp to String in the Select statement via TO_CHAR function:
select id,TO_CHAR(precisetime, 'YYYY-MM-DD HH:MI:SS.FF') ptime from precisetimes
where TO_CHAR(precisetime, 'YYYY-MM-DD HH:MI:SS.FF') > '2017-05-31 12:12:12.123457';
result:
ID PTIME
---------- -----------------------------
1 2017-05-31 12:12:12.123456
2 2017-05-31 12:12:12.120000
BUT for this you have to use JPA's Criteria api or native query because native functions are not supported in JPQL. In this case also be careful to use the same format on the DB side and on the Java side.