1

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.mypackage.mysubpackage.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();
    }
}

I am using ormlite-core-4.49-SNAPSHOT.jar.

What should I look for correcting this?

6
  • Did you add ormlite-jdbc library also? Commented Feb 28, 2016 at 11:29
  • Yes, I did. Same version as ormlite-core. Commented Feb 28, 2016 at 12:08
  • I suspect there is more to the exception. Can you provide the full exception? The last caused by is critical. Commented Feb 28, 2016 at 19:57
  • Actually that is the last one. I cut it as last lines just refer to my classes Commented Feb 28, 2016 at 20:19
  • @Manu maybe the problem is connected with protected constructors for your entities? Commented Feb 29, 2016 at 7:17

1 Answer 1

1

For me solution has been to switch to ormlite-core-4.48. Same version for ormlite-jdbc driver. Now it works correctly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.