I am trying to get records using JPA Query, which has DATE and TIMESTAMP columns in a WHERE clause. But for some reason, the date and time columns cannot extract anything from the database.
Code Segment:
String sql = "Select F.* from FIN_TABLE F where F.COL1_NUM = :COL1 and F.COL2_TIMESTAMP =:COL2 and F.COL3_DATE =:COL3";
Query query = JPAentityManager.createNativeQuery(sql);
query.setParameter("COL1", 123);
query.setParameter("COL2", new java.sql.Timestamp(new java.sql.Date(new SimpleDateFormat("MMM dd yyyy HH:mm:sssa").parse("OCT 29 2014 12:00:000AM").getTime()).getTime()));
query.setParameter("COL3", new java.sql.Date(new SimpleDateFormat("MMM dd yyyy HH:mm:sssa").parse("OCT 29 2014 12:00:000AM").getTime()));
List<FinTable> result = (List<FinTable>)query.getResultList();
And the data in Oracle:
COL1_NUM COL2_TIMESTAMP COL3_DATE
123 29-OCT-14 12.00.00.000000000 AM 26-Nov-14
456 29-OCT-14 12.00.00.000000000 AM 26-Nov-14
I initially try to get the results using EntityManager.find (class, object), but it also failed, so I tried with createNativeQuery (), which also failed. My FinTable object has these columns as Timestamp and Date.
Please enlighten the right way. :) Thank you!