2014-10-21 74 views
1

你好我正面臨一個問題:ORMLITE一對多遞歸關係

我需要存儲主題的樹表示。

我的意思是一個主題對對象類型

@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; 

這個代碼拋出錯誤

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存儲樹結構的兒童名單???

+0

的是不是有什麼問題與您的CapsLock鍵,或者是你的問題,所以迫切和重要,你必須要喊的稱號!? – 2014-10-21 22:02:26

+0

是的抱歉是緊急的...我會嘗試改變CAP – 2014-10-21 22:07:44

回答

1

嘗試改變兒子鍵入類型ForeignCollection

@ForeignCollectionField 
private ForeignCollection<Subject> sons; 
+0

謝謝,它的作品 – 2014-10-22 14:34:14

+0

兒子是否持有主題權限列表? – 2017-12-05 11:15:46