Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io.objectbox.exception.DbException: Could not begin read transaction (another read transaction is still active on this thread) (error code -30783) #563

Closed
wb1992321 opened this issue Sep 20, 2018 · 10 comments
Assignees

Comments

@wb1992321
Copy link

ObjectBox Version:2.1.0

@Entity
public class TaskObj {
      @Convert(converter = TagConverter.class, dbType = String.class)
      private List<TagObj> tags;
}
public final class TagConverter implements PropertyConverter<List<TagObj>, String> {

    @Override
    public List<TagObj> convertToEntityProperty(String databaseValue) {
        return ConvertUtils.query(databaseValue, TagObj_.id, TagObj.class);
    }

    @Override
    public String convertToDatabaseValue(List<TagObj> entityProperty) {
        return TagObj.save(entityProperty);
    }
}
public final class ConvertUtils {

    public static <T> List<T> query(String databaseValue, Property<T> property, Class<T> c) {
        if (TextUtils.isEmpty(databaseValue)) {
            return null;
        } else {
            List<Long> ids = JSONUtils.parseArray(databaseValue, Long.class);

//            return App.instance()
//                    .getBox().boxFor(c)
//                    .get(ids);
            long[] id = new long[ids.size()];
            for (int i = 0; i < ids.size(); i++) {
                id[i] = ids.get(i);
            }
            return App.instance().getBox().boxFor(c)
                    .query()
                    .in(property, id)
                    .build().find();
        }
    }

}
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.assistant.one/com.assistant.one.ui.activity.AlarmActivity}: io.objectbox.exception.DbException: Could not begin read transaction (another read transaction is still active on this thread) (error code -30783)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6940)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
     Caused by: io.objectbox.exception.DbException: Could not begin read transaction (another read transaction is still active on this thread) (error code -30783)
        at io.objectbox.BoxStore.nativeBeginReadTx(Native Method)
        at io.objectbox.BoxStore.beginReadTx(BoxStore.java:371)
        at io.objectbox.BoxStore.callInReadTx(BoxStore.java:706)
        at io.objectbox.BoxStore.callInReadTxWithRetry(BoxStore.java:654)
        at io.objectbox.query.Query.callInReadTx(Query.java:273)
        at io.objectbox.query.Query.find(Query.java:193)
        at com.assistant.one.bean.db.ConvertUtils.query(ConvertUtils.java:35)
        at com.assistant.one.bean.db.TagConverter.convertToEntityProperty(TagConverter.java:19)
        at com.assistant.one.bean.db.TagConverter.convertToEntityProperty(TagConverter.java:15)
        at io.objectbox.Cursor.nativeGetEntity(Native Method)
        at io.objectbox.Cursor.get(Cursor.java:186)
        at io.objectbox.Box.get(Box.java:209)
        at com.assistant.one.ui.activity.AlarmActivity.initData(AlarmActivity.java:212)
        at com.assistant.one.ui.activity.AlarmActivity.onCreate(AlarmActivity.java:122)
        at android.app.Activity.performCreate(Activity.java:7174)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) 
        at android.os.Handler.dispatchMessage(Handler.java:105) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6940) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) 
09-20 16:02:01.797 24723-24723/com.assistant.one E/CrashReport: # CRASH STACK: 
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.assistant.one/com.assistant.one.ui.activity.AlarmActivity}: io.objectbox.exception.DbException: Could not begin read transaction (another read transaction is still active on this thread) (error code -30783)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6940)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
     Caused by: io.objectbox.exception.DbException: Could not begin read transaction (another read transaction is still active on this thread) (error code -30783)
        at io.objectbox.BoxStore.nativeBeginReadTx(Native Method)
        at io.objectbox.BoxStore.beginReadTx(BoxStore.java:371)
        at io.objectbox.BoxStore.callInReadTx(BoxStore.java:706)
        at io.objectbox.BoxStore.callInReadTxWithRetry(BoxStore.java:654)
        at io.objectbox.query.Query.callInReadTx(Query.java:273)
        at io.objectbox.query.Query.find(Query.java:193)
        at com.assistant.one.bean.db.ConvertUtils.query(ConvertUtils.java:35)
        at com.assistant.one.bean.db.TagConverter.convertToEntityProperty(TagConverter.java:19)
        at com.assistant.one.bean.db.TagConverter.convertToEntityProperty(TagConverter.java:15)
        at io.objectbox.Cursor.nativeGetEntity(Native Method)
        at io.objectbox.Cursor.get(Cursor.java:186)
        at io.objectbox.Box.get(Box.java:209)
        at com.assistant.one.ui.activity.AlarmActivity.initData(AlarmActivity.java:212)
        at com.assistant.one.ui.activity.AlarmActivity.onCreate(AlarmActivity.java:122)
        at android.app.Activity.performCreate(Activity.java:7174)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) 
        at android.os.Handler.dispatchMessage(Handler.java:105) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6940) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) 
    #++++++++++++++++++++++++++++++++++++++++++#
@wb1992321
Copy link
Author

@greenrobot
It is reproducible!

@greenrobot
Copy link
Member

Reproducible is great! Is there a sample project to reproduce?

@wb1992321
Copy link
Author

@greenrobot
Our project is absolutely reproducible, the main code is those!

@greenrobot-team
Copy link
Member

You probably should not use Box methods inside the convertToEntityProperty() method.

This looks like a hack to do relations on your own. I suggest using a ToMany relation instead of mapping IDs to entities yourself.
-ut

@greenrobot
Copy link
Member

greenrobot commented Sep 25, 2018

@greenrobot-team Good catch, we should explicitly forbid any DB access inside a converter in the docs (online & JavaDocs).

@wb1992321
Copy link
Author

@greenrobot
ToMany does not have a convenient List, especially for json data parsing.

@wb1992321
Copy link
Author

@greenrobot
ToMany has no parameterless constructor, and there are problems with instantiation. It is also a lot of inconvenience to convert List to ToMany.

@wb1992321
Copy link
Author

private ToMany<TagObj> tags;

public void setTags(ToMany<TagObj> tags) {
        this.tags = tags;
    }

    public void setTags(List<TagObj> tags) {
        this.tags = tags;
    }

There is a problem with this implementation, but I have to need a second function

@greenrobot
Copy link
Member

We'll address improved List handling; see #104

@greenrobot-team
Copy link
Member

greenrobot-team commented Oct 1, 2018

Added note to docs.

6df464c Amended PropertyConverter JavaDoc.
-ut

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants