I have a date which created from current time and the object type is XMLGregorianCalendar. In Java, I can see that my date has microseconds but in the SQL, it is set as 0. What is the exact problem here?
public static XMLGregorianCalendar initializeTime(LocalDateTime localDateTime) {
try {
XMLGregorianCalendar time= DatatypeFactory.newInstance()
.newXMLGregorianCalendar(String.valueOf
(LocalDateTime.now().truncatedTo(ChronoUnit.MICROS)));
return time;
} catch (DatatypeConfigurationException var3) {
throw new RuntimeException("Execution time could not created.");
}
}
In Java it shows: 2023-05-24T15:50:07.931456
But in the SQL (the type is TIMESTAMP(6)) it shows like this : 24-MAY-23 15.50.07.931000000 PM
SQL calling, you can find it down below. dummytest is a procedure basically taking a param and inserting this param into a table.
<select id="add_time" statementType="CALLABLE" parameterType="java.util.Map">
{call dummytest(
#{time, mode=IN, jdbcType=TIMESTAMP}
)}
</select>
procedure code:
create or replace procedure dummytest(p_timestamp TIMESTAMP) is
begin
insert into testtimestamp values (p_timestamp);
commit;
end ;
I am losing the microsecond precision. I have to use XMLGregorianCalendar because all code designed for this API.
The problem is fixed by custom handler in java side.
Content of XMLGregorianCalendarWithFractionalTypeHandler: