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