我试图在我的JavaFX应用程序中保留一些数据。 尝试在PersistenceManager类中创建表时,我的代码失败:
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);
实际创建了文件my.db
,但它是空的。执行TableUtils.createTable时,它会触发以下内容:
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)
我的班级是这样的:
@DatabaseTable(tableName = "myclass")
public class MyClass {
@DatabaseField(id = true)
private String nome;
@ForeignCollectionField(eager = false)
private Collection<MyOtherClass> risposte;
protected MyClass() {
super();
}
}
和MyOtherClass是:
@DatabaseTable(tableName = "myotherclass")
public class MyOtherClass {
@DatabaseField(id = true)
private String nome;
@DatabaseField(foreign = true)
private MyClass scheda;
protected MyOtherClass() {
super();
}
}
我正在使用ormlite-core-4.49-SNAPSHOT.jar
。
我该如何纠正这个?
答案 0 :(得分:1)
对我来说,解决方案是切换到ormlite-core-4.48。 ormlite-jdbc驱动程序的版本相同。现在它正常工作。