2

I'm trying to use ActiveJDBC with HSQLDB:

Base.open("org.hsqldb.jdbc.JDBCDriver", "jdbc:hsqldb:file:queen-db;shutdown=true;hsqldb.write_delay=false;", "sa", "");

    User e = new User();
    e.set("id", 1);
    e.set("nickname", "Superman");
    e.set("first_name", "John");
    e.set("last_name", "Doe");
    e.saveIt();

    User e1 = new User();
    e1.set("id", 2);
    e1.set("nickname", "Superman2");
    e1.set("first_name", "John2");
    e1.set("last_name", "Doe2");
    e1.saveIt();

    List<User> users = User.findAll();

    for (User user : users) {
        System.out.println(user.get("id") + " " + user.get("nickname") + " " + user.get("first_name") + " " + user.get("last_name"));
    }

but having no output, and there are no information in DB. Here is my FlyWay migration:

CREATE TABLE users (
    id INT NOT NULL,
    nickname VARCHAR(100) NOT NULL,
    first_name VARCHAR(100) NOT NULL,
    last_name VARCHAR(100) NOT NULL
);

What's wrong?

ADD: Setted up Log4J, got messages:

0    [main] INFO  hsqldb.db.HSQLDB3F3E800675.ENGINE  - checkpointClose start
35   [main] INFO  hsqldb.db.HSQLDB3F3E800675.ENGINE  - checkpointClose end

UPDATE: here is log output

0    [main] INFO  hsqldb.db.HSQLDB3F42F00869.ENGINE  - checkpointClose start
37   [main] INFO  hsqldb.db.HSQLDB3F42F00869.ENGINE  - checkpointClose end
68   [main] INFO  org.javalite.activejdbc.ConnectionsAccess  - Attaching connection: org.hsqldb.jdbc.JDBCConnection@41a78257
68   [main] INFO  org.javalite.activejdbc.ConnectionsAccess  - Opened connection:org.hsqldb.jdbc.JDBCConnection@41a78257 named: default on thread: Thread[main,5,main]
97   [main] INFO  org.javalite.activejdbc.Configuration  - Load models from: jar:file:/Users/dmitrysavchenko/projects/hive-queen/target/queen-jar-with-dependencies.jar!/activejdbc_models.properties
116  [main] INFO  org.javalite.activejdbc.Registry  - Registered model: class org.hive.models.User
285  [main] INFO  org.javalite.activejdbc.Registry  - Fetched metadata for table: users
302  [main] INFO  org.javalite.activejdbc.DB  - Query: "UPDATE users SET first_name= ?, nickname= ?, last_name= ? where id = ?", with parameters: <John>, <Superman>, <Doe>, <1>, took: 11 milliseconds
305  [main] INFO  org.javalite.activejdbc.DB  - Query: "UPDATE users SET first_name= ?, nickname= ?, last_name= ? where id = ?", with parameters: <John2>, <Superman2>, <Doe2>, <2>, took: 0 milliseconds
315  [main] INFO  org.javalite.activejdbc.LazyList  - Query: "SELECT * FROM users", took: 4 milliseconds

Looks like a wrong operation performed. What's wrong?

skayred
  • 10,603
  • 10
  • 52
  • 94
  • What are time timestamps of those messages? – Mubin Jun 13 '13 at 17:51
  • Enable logging by adding system property -Dactivejdbc.log It will then output every generated SQL statement that is sent to DB. – Mubin Jun 13 '13 at 18:35
  • just want to point out, that ActiveJDBC supports the following databases: MySQL, PostgreSQL, Oracle, H2 and MS SQLServer – ipolevoy Jun 13 '13 at 22:03
  • And no HSQLDB support? It is supported by JDBC – skayred Jun 14 '13 at 02:39
  • If you are using a recent version of HSQLDB, I would say that your JDBC driver class looks wrong. Mine is "org.hsqldb.jdbcDriver". Also, make certain that the driver is available on your class path. It is actually a little simpler to use HSQLDB in server mode in this respect ... you always at least know if it is configured properly since it won't start up if not. – scottb Jun 14 '13 at 06:00
  • @skayred: HSQLDB has quite a full-featured JDBC 4.1 driver. – scottb Jun 14 '13 at 06:04
  • I've added some SQL output, see edit – skayred Jun 14 '13 at 13:49

1 Answers1

2

My problem was in ID attribute. Default ActiveJDBC behaviour is following: if ID attribute is null, it creates record, and if there are any value, it updates it. In my case I've just used the following code:

User e = new User();
e.set("id", 1);
e.set("nickname", "Superman");
e.set("first_name", "John");
e.set("last_name", "Doe");
e.insert();

Important! insert is not available on old version, so use 1.4.7 or higher

skayred
  • 10,603
  • 10
  • 52
  • 94