brettwooldridge / SansOrm

A "No-ORM" sane SQL ←→ Java object mapping library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Timestamps lose microseconds in OrmBase.mapSqlType

dletin opened this issue · comments

java.sql.Timestamp is instance of java.util.Date.
The code below (in OrmBase.mapSqlType) truncates Timestamp precision to milliseconds

  case Types.TIMESTAMP:
     if (object instanceof java.util.Date) {
        return new Timestamp(((java.util.Date) object).getTime());  // << microseconds are lost if object is already a Timestamp
     }
     break;

Simple solution:

  case Types.TIMESTAMP:
     if (object instanceof Timestamp) {
        return object;
     }
     if (object instanceof java.util.Date) {
        return new Timestamp(((java.util.Date) object).getTime());
     }
     break;

Thanks for reporting this! I've added your change and I think we'll try to push an update to maven central in the next day or so.

I asked @brettwooldridge if he can figure out how to give me privileges to publish to maven.

  • Leo

sansorm-2.3 has been released to maven central.