0

I'm having trouble reading a Model from db using ActiveJDBC.

Basically, i'm doing ModelClass.findFirst(...) and a SQLException pops up. There seem to be no problems if the timestamp field is non-zero.

Said Model has a mysql timestamp (tried also datetime) field with zero / null value in it. This example is a timestamp with value '0000-00-00 00:00:00'. Model object is populated without errors if i update the value to a real date/time.

Caused by: java.sql.SQLException: Value '10151payment100.0012002017-01-16 02:06:530000-00-00 00:00:002017-01-16 03:36:43noFirst Last
+358 40 123456b989e4dce9e639eaadbed3b64e2c3eb' can not be represented as java.sql.Timestamp

My question is - i need to store an arbitrary date+time in this column, and for convenience reasons it should be null or zero if a value has not been stored. Is this a possible combination with ActiveJDBC?

EDIT: A minimal example to reproduce below.

Table

CREATE TABLE test (
  id int(10) unsigned NOT NULL AUTO_INCREMENT,
  ts timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
insert into test (id) values (1);

Model source

import org.javalite.activejdbc.Model;
import org.javalite.activejdbc.annotations.Table;

@Table("test")
public class Test extends Model {

}

Main class

import com.zaxxer.hikari.HikariDataSource;
import javax.sql.DataSource;
import org.javalite.activejdbc.Base;

public class ActiveJDBCTest {
    private HikariDataSource dbds;
    public ActiveJDBCTest() {
        try {
            init();            
        } catch (Exception e) {
            System.out.println(e);
        }
    }

    public void init() throws ClassNotFoundException {
        Class.forName("com.mysql.jdbc.Driver");
        dbds = new HikariDataSource();
        dbds.setJdbcUrl("jdbc:mysql://localhost:3306/test" +
                "?useSSL=false" +
                "&characterEncoding=UTF-8");
        dbds.setUsername("test");
        dbds.setPassword("test");
        dbds.setConnectionInitSql("SET @@session.time_zone = '+00:00'");
        Base.open(dbds);
        Test first = Test.findFirst("id = ?", 1);
        Base.close();
    }

    public static void main(String[] args) {
        new ActiveJDBCTest();
    }
}

Result (please see embedded image for actual exception message - null characters?)

org.javalite.activejdbc.DBException: java.sql.SQLException: Value '10000-00-00 00:00:00' can not be represented as java.sql.Timestamp

Result

Hitunen
  • 11
  • 2

2 Answers2

0

Without a full stack trace and DDL, I can only see that you have the following value in your column:

10151payment100.0012002017-01-16 02:06:530000-00-00 00:00:002017-01-16 03:36:43noFirst Last
+358 40 123456b989e4dce9e639eaadbed3b64e2c3eb

The MySQL driver is telling you that it can not be represented as java.sql.Timestamp. I think you some sort of data corruption issue. I do not think it is related to ActiveJDBC.

ipolevoy
  • 5,432
  • 2
  • 31
  • 46
0

Ohh hell, i'm sorry for wasting your time. I apparently figured it out.

The underlying db has at some point changed from mysql to mariadb - it's some driver incompatibility while using mysql connector/j with mariadb. Using mariadb driver makes the problem go away.

Hitunen
  • 11
  • 2