ORMLITE一对许多递归关系

ORMLITE一对许多递归关系

本文介绍了ORMLITE一对许多递归关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我面临的一个问题:

Hello i am facing a problem:

我需要存储的对象树重新presentation。

I need to store a tree representation of subjects.

我的意思是受试者是否有对象类型的儿童名单

I mean a SUBJECT have a list of childrens of type SUBJECT

 @DatabaseTable(tableName = "subject")
public class Subject implements Serializable {

@DatabaseField(columnName = "_id")
private int id;
@DatabaseField
private String text;

@DatabaseField(columnName = "parent", foreign = true)
private Subject parent;

@ForeignCollectionField
private List<Subject> sons;

这code抛出一个错误

this code throws an error

 9950-9950/ec.com.smx.flux E/EC.COM.SMX.FLUX/SubjectDaoProvider.java:25﹕ main java.sql.SQLException: Field class for 'sons' must be of class ForeignCollection or Collection.
            at com.j256.ormlite.field.FieldType.<init>(FieldType.java:167)
            at com.j256.ormlite.table.DatabaseTableConfig.convertFieldConfigs(DatabaseTableConfig.java:236)
            at com.j256.ormlite.table.DatabaseTableConfig.extractFieldTypes(DatabaseTableConfig.java:101)
            at com.j256.ormlite.dao.BaseDaoImpl.initialize(BaseDaoImpl.java:151)
            at com.j256.ormlite.dao.BaseDaoImpl.<init>(BaseDaoImpl.java:126)
            at com.j256.ormlite.dao.BaseDaoImpl.<init>(BaseDaoImpl.java:117)
            at com.j256.ormlite.dao.BaseDaoImpl$5.<init>(BaseDaoImpl.java:919)
            at com.j256.ormlite.dao.BaseDaoImpl.createDao(BaseDaoImpl.java:919)
            at com.j256.ormlite.dao.DaoManager.createDao(DaoManager.java:72)
            at com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper.getDao(OrmLiteSqliteOpenHelper.java:277)
            at ec.com.smx.flux.data.DatabaseHelperImpl.getSubjectDao(DatabaseHelperImpl.java:372)
            at ec.com.smx.flux.data.conf.SubjectDaoProvider.get(SubjectDaoProvider.java:23)
            at ec.com.smx.flux.data.conf.SubjectDaoProvider.get(SubjectDaoProvider.java:14)
            at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:86)
            at com.google.inject.internal.BoundProviderFactory.provision(BoundProviderFactory.java:73)
            at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:66)
            at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:63)
            at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
            at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1058)
            at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
            at com.google.inject.Scopes$1$1.get(Scopes.java:65)
            at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
            at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:205)
            at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:199)
            at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1051)
            at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:199)
            at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:180)
            at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
            at com.google.inject.Guice.createInjector(Guice.java:96)
            at com.google.inject.Guice.createInjector(Guice.java:84)
            at roboguice.RoboGuice.setBaseApplicationInjector(RoboGuice.java:94)
            at ec.com.smx.flux.FluxApplication.onCreate(FluxApplication.java:53)
            at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1025)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4581)
            at android.app.ActivityThread.access$1600(ActivityThread.java:161)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1325)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:157)
            at android.app.ActivityThread.main(ActivityThread.java:5356)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
            at dalvik.system.NativeStart.main(Native Method)

有谁能够告诉我怎么用ormlite ???存储一个树形结构

can anybody show me how to store a tree structure using ormlite???

推荐答案

试着改变儿子型,将ForeignCollection的

Try changing the sons type to type of ForeignCollection

@ForeignCollectionField
private ForeignCollection<Subject> sons;

这篇关于ORMLITE一对许多递归关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 04:05