Thursday, 15 July 2010

java - ORMLite iterating over ForeignCollection throws the exception -



java - ORMLite iterating over ForeignCollection throws the exception -

i seek iterate on foreigncollection<orderitems>. works if eager set true lazy alternative still doesn't work.

firstly, make

orderdatasource orderds = new orderdatasource(getappcontext()); ws.order order = orderds.converttows(morder,ws.order.class); orderds.close();

where close() close db connection , converttows() create iterating.

part of converttows():

iterator<orderitem> itr = order.getorderitems().iterator(); while (itr.hasnext()) { orderitem orderitem = itr.next(); ... }

method close called after homecoming converttows(). work other objects in converttows() problem.

i seek utilize closeableiterator , close in finally block, without success. expect of this, don't close connection.

exception:

02-17 02:21:43.094: e/androidruntime(4820): fatal exception: main 02-17 02:21:43.094: e/androidruntime(4820): java.lang.illegalstateexception: database /data/data/my_app/databases/my_db (conn# 0) closed 02-17 02:21:43.094: e/androidruntime(4820): @ android.database.sqlite.sqlitedatabase.verifydbisopen(sqlitedatabase.java:2082) 02-17 02:21:43.094: e/androidruntime(4820): @ android.database.sqlite.sqlitedatabase.rawquerywithfactory(sqlitedatabase.java:1556) 02-17 02:21:43.094: e/androidruntime(4820): @ android.database.sqlite.sqlitedatabase.rawquery(sqlitedatabase.java:1538) 02-17 02:21:43.094: e/androidruntime(4820): @ com.j256.ormlite.android.androidcompiledstatement.getcursor(androidcompiledstatement.java:162) 02-17 02:21:43.094: e/androidruntime(4820): @ com.j256.ormlite.android.androidcompiledstatement.runquery(androidcompiledstatement.java:57) 02-17 02:21:43.094: e/androidruntime(4820): @ com.j256.ormlite.stmt.selectiterator.<init>(selectiterator.java:55) 02-17 02:21:43.094: e/androidruntime(4820): @ com.j256.ormlite.stmt.statementexecutor.builditerator(statementexecutor.java:232) 02-17 02:21:43.094: e/androidruntime(4820): @ com.j256.ormlite.dao.basedaoimpl.createiterator(basedaoimpl.java:933) 02-17 02:21:43.094: e/androidruntime(4820): @ com.j256.ormlite.dao.basedaoimpl.iterator(basedaoimpl.java:531) 02-17 02:21:43.094: e/androidruntime(4820): @ com.j256.ormlite.dao.basedaoimpl.iterator(basedaoimpl.java:526) 02-17 02:21:43.094: e/androidruntime(4820): @ com.j256.ormlite.dao.lazyforeigncollection.seperateiteratorthrow(lazyforeigncollection.java:74) 02-17 02:21:43.094: e/androidruntime(4820): @ com.j256.ormlite.dao.lazyforeigncollection.iteratorthrow(lazyforeigncollection.java:60) 02-17 02:21:43.094: e/androidruntime(4820): @ com.j256.ormlite.dao.lazyforeigncollection.closeableiterator(lazyforeigncollection.java:50) 02-17 02:21:43.094: e/androidruntime(4820): @ com.j256.ormlite.dao.lazyforeigncollection.iterator(lazyforeigncollection.java:45) 02-17 02:21:43.094: e/androidruntime(4820): @ com.j256.ormlite.dao.lazyforeigncollection.iterator(lazyforeigncollection.java:26) 02-17 02:21:43.094: e/androidruntime(4820): @ orders.orderdatasource.converttows(orderdatasource.java:409) 02-17 02:21:43.094: e/androidruntime(4820): @ fragments.orderdetailfragment.sendorder(orderdetailfragment.java:419) 02-17 02:21:43.094: e/androidruntime(4820): @ fragments.orderdetailfragment.dopositiveclick(orderdetailfragment.java:347) 02-17 02:21:43.094: e/androidruntime(4820): @ ui.dialogfragments.alertdialogfragment$1.onclick(alertdialogfragment.java:54) 02-17 02:21:43.094: e/androidruntime(4820): @ com.android.internal.app.alertcontroller$buttonhandler.handlemessage(alertcontroller.java:166) 02-17 02:21:43.094: e/androidruntime(4820): @ android.os.handler.dispatchmessage(handler.java:99) 02-17 02:21:43.094: e/androidruntime(4820): @ android.os.looper.loop(looper.java:137) 02-17 02:21:43.094: e/androidruntime(4820): @ android.app.activitythread.main(activitythread.java:4424) 02-17 02:21:43.094: e/androidruntime(4820): @ java.lang.reflect.method.invokenative(native method) 02-17 02:21:43.094: e/androidruntime(4820): @ java.lang.reflect.method.invoke(method.java:511) 02-17 02:21:43.094: e/androidruntime(4820): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:784) 02-17 02:21:43.094: e/androidruntime(4820): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:551) 02-17 02:21:43.094: e/androidruntime(4820): @ dalvik.system.nativestart.main(native method)

you need have database open in order iterate on values since doing lazy queries, meaning fetching info database first time access object foreign collection.

so if extending ormliteactivity database remain open until destroy screen.

the main thing here maintain helper open while using data.

java android collections ormlite foreign-collection

No comments:

Post a Comment