I have a student_audit
table where I am storing some audit information for the student.
The table has existing data.
ID | NAME | AUDIT_TIMESTAMP
___________________________
1 | TEST | 22-JUN-22 07.23.59.515462000 AM
The DDL for the table is as follows:
CREATE TABLE student_audit (
id NUMBER(8) NOT NULL,
name VARCHAR2(20 BYTE) NOT NULL,
audit_timestamp TIMESTAMP NOT NULL,
CONSTRAINT pk_stdnt_aud PRIMARY KEY (id)
);
I have a mapper method in StudentDao.java
StudentEntity getStudent(@Param("name") String name,
@Param("auditTimestamp") Timestamp auditTimestamp)
public class StudentEntity {
private Integer id;
private String name;
// java.sql.Timestamp
private Timestamp auditTimestamp;
// getters and setters
}
The StudentDao.xml
method is as follows
<resultMap id="studentMap"
type="fully-qualified-name-of-StudentEntity ">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="auditTimestamp" column="auditTimestamp"/>
</resultMap>
<select id="getStudent"
resultMap="studentMap">
SELECT
s.id
, s.name
, s.audit_timestamp as auditTimestamp
FROM
student_audit s
WHERE
s.audit_timestamp = #{auditTimestamp}
</select>
When I run an integration test against this Dao method, its always returning null. However, the following query in SQL developer is returning the value.
select * from student_audit
where audit_timestamp = TO_TIMESTAMP('2022-06-22 07:23:59.515462', 'YYYY-MM-DD HH24:MI:SS.FF');
I tried the following solutions:
- Using the
SqlTimestampTypeHandler
along with the audit timestamp value - Using
jdbcType
attribute
I have not been able to resolve this.
Adding logs from the console
11:44:46.495 [main] DEBUG c.c.w.f.e.p.r.StudentDao.getStudent - ==> Preparing: SELECT s.id, s.name, s.audit_timestamp as auditTimestamp FROM student_audit s WHERE s.audit_timestamp = ?
11:44:46.551 [main] DEBUG c.c.w.f.e.p.r.StudentDao.getStudent - ==> Parameters: 2022-06-22 07:23:59.515462(Timestamp)
11:44:47.240 [main] DEBUG c.c.w.f.e.p.r.StudentDao.getStudent - <== Total: 0