Search code examples
mysqlactivejdbc

ActiveJDBC ignores the time in a DATETIME column


Using ActiveJDBC with MySQL, the column declaration:

`start` datetime NOT NULL

Java Model:

    public class MyTable extends Model {
        private static final String COL_START = "start";
        ...
        public Date getStart() {
            return getDate(COL_START);
        }
    }

I only get the date like yyyy-MM-dd, the time (HH:mm:ss) is missing. Same thing when I want to save a date, the hours/minutes/seconds are not saved.
Why?
Thanks!


Solution

  • The answer is in the name of the method. You are asking for a date, and not date with time. The JavaDoc: http://javalite.github.io/activejdbc/org/javalite/activejdbc/Model.html#getDate-java.lang.String- .

    You need to use:

    public class MyTable extends Model {
        private static final String COL_START = "start";
        ...
        public Timestamp getStart() {
            return getTimestamp(COL_START);
        }
    }
    

    in order to get date with a time component.