JetBrains/xodus-dnq

XdEntity.findById() throws ReadonlyTransactionException: Can't create a store in read-only transaction

jansorg opened this issue · 3 comments

I'm getting this exception when I run the test program below. Afaik this should throw a EntityRemovedInDatabaseException. At least this is what jetbrains.exodus.entitystore.StoreTransaction#getEntity has in the docs.

Ids in the form generated by Xodus can always be entered by users or send by external services.

As always, I'm sorry if I misunderstood the API...

Exception:

Exception in thread "main" jetbrains.exodus.env.ReadonlyTransactionException: Can't create a store in read-only transaction
	at jetbrains.exodus.env.EnvironmentImpl.throwIfReadonly(EnvironmentImpl.java:904)
	at jetbrains.exodus.env.EnvironmentImpl.openStoreImpl(EnvironmentImpl.java:784)
	at jetbrains.exodus.env.EnvironmentImpl.openStore(EnvironmentImpl.java:191)
	at jetbrains.exodus.env.EnvironmentImpl.openStore(EnvironmentImpl.java:51)
	at jetbrains.exodus.entitystore.tables.SingleColumnTable.<init>(SingleColumnTable.java:33)
	at jetbrains.exodus.entitystore.PersistentEntityStoreImpl$2$2.createTable(PersistentEntityStoreImpl.java:248)
	at jetbrains.exodus.entitystore.OpenTablesCache.get(OpenTablesCache.java:45)
	at jetbrains.exodus.entitystore.PersistentEntityStoreImpl.getEntitiesTable(PersistentEntityStoreImpl.java:1842)
	at jetbrains.exodus.entitystore.PersistentEntityStoreImpl.getLastVersion(PersistentEntityStoreImpl.java:1488)
	at jetbrains.exodus.entitystore.PersistentStoreTransaction.getEntity(PersistentStoreTransaction.java:276)
	at com.jetbrains.teamsys.dnq.database.TransientSessionImpl.getEntity(TransientSessionImpl.kt:257)
	at kotlinx.dnq.util.IdsKt.findById(Ids.kt:27)
	at com.logrally.server.TestKt$main$1.invoke(test.kt:27)
	at com.logrally.server.TestKt$main$1.invoke(test.kt)
	at com.jetbrains.teamsys.dnq.database.TransientEntityStoreExt.transactional(TransientEntityStoreExt.kt:51)
	at com.jetbrains.teamsys.dnq.database.TransientEntityStoreImpl.transactional(TransientEntityStoreImpl.kt:95)
	at jetbrains.exodus.database.TransientEntityStore$DefaultImpls.transactional$default(TransientEntityStore.kt:84)
	at com.logrally.server.TestKt.main(test.kt:26)

Code:

package com.logrally.server

import jetbrains.exodus.entitystore.Entity
import kotlinx.dnq.XdEntity
import kotlinx.dnq.XdModel
import kotlinx.dnq.XdNaturalEntityType
import kotlinx.dnq.store.container.StaticStoreContainer
import kotlinx.dnq.util.findById
import kotlinx.dnq.util.initMetaData
import java.io.File

class TestEntity(entity: Entity) : XdEntity(entity) {
    companion object : XdNaturalEntityType<TestEntity>()
}

fun main(args: Array<String>) {
    XdModel.registerNode(TestEntity)

    val dir = File("test_entity_store")
    if (dir.exists()) {
        dir.deleteRecursively()
    }

    val store = StaticStoreContainer.init(dir, "db")
    initMetaData(XdModel.hierarchy, store)
    store.transactional {
        TestEntity.findById("42-42")
    }
}

This is actually a bug, thanks for reporting!

@lehvolk My pull request is not merged yet.

@penemue done.