dimanche 28 février 2016

Embedded Sqlite database with Ormlite and JavaFX: error creating table

I am trying to persist some data in my JavaFX application. My code fails when attempting to create a table in my PersistenceManager class:

private final static String DATABASE_URL = "jdbc:sqlite:my.db";
private final static String DATABASE_DRIVER = "org.sqlite.JDBC";
// ...
    Class.forName(DATABASE_DRIVER);
    DriverManager.getConnection(DATABASE_URL);
    connectionSource = new JdbcConnectionSource(DATABASE_URL);
    // here it fails:
    TableUtils.createTable(connectionSource,MyClass.class);

A file my.db is actually created, but it is empty. When executing TableUtils.createTable, it triggers the following:

Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
    ... 43 more
Caused by: java.lang.AbstractMethodError: com.j256.ormlite.jdbc.JdbcDatabaseConnection.compileStatement(Ljava/lang/String;Lcom/j256/ormlite/stmt/StatementBuilder$StatementType;[Lcom/j256/ormlite/field/FieldType;I)Lcom/j256/ormlite/support/CompiledStatement;
    at com.j256.ormlite.table.TableUtils.doStatements(TableUtils.java:458)
    at com.j256.ormlite.table.TableUtils.doCreateTable(TableUtils.java:441)
    at com.j256.ormlite.table.TableUtils.createTable(TableUtils.java:221)
    at com.j256.ormlite.table.TableUtils.createTable(TableUtils.java:54)
    at org.lh.inquadramentopupilla.persistence.PersistenceManager.<init>(PersistenceManager.java:32)

My Class is this:

@DatabaseTable(tableName = "myclass")
public class MyClass {
    @DatabaseField(id = true)
    private String nome;

    @ForeignCollectionField(eager = false)
    private Collection<MyOtherClass> risposte;

    protected MyClass() {
        super();
    }
}

and MyOtherClass is:

@DatabaseTable(tableName = "myotherclass")
public class MyOtherClass {
    @DatabaseField(id = true)
    private String nome;

    @DatabaseField(foreign = true)
    private MyClass scheda;

    protected MyOtherClass() {
        super();
    }
}

What should I look for correcting this?

Aucun commentaire:

Enregistrer un commentaire