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

Many-to-many: NoSuchElementException: List is empty #708

Closed
matthjes opened this issue Dec 1, 2019 · 3 comments
Closed

Many-to-many: NoSuchElementException: List is empty #708

matthjes opened this issue Dec 1, 2019 · 3 comments
Labels

Comments

@matthjes
Copy link

matthjes commented Dec 1, 2019

Hi,

I'm trying to get a many-to-many relationship working. Here are the relevant classes:

object Fragments : IdTable<Long>(name = "fragments") {
    override val id = long("id").primaryKey().entityId()
    val contentText = text("content_text")
    val contentBinary = blob("content_binary")
}

class Fragment(timestamp: EntityID<Long>) : LongEntity(timestamp) {
    companion object : LongEntityClass<Fragment>(Fragments)

    var contentText by Fragments.contentText
    var contentBinary by Fragments.contentBinary
    var contexts by ContextElement via FragmentToContexts
}

object ContextElements : LongIdTable(name = "context_elements") {
    val name = text("name")
}

class ContextElement(id: EntityID<Long>) : LongEntity(id) {
    companion object : LongEntityClass<ContextElement>(ContextElements)

    var name by ContextElements.name
    var parents by ContextElement.via(ContextToContexts.child, ContextToContexts.parent)
    var children by ContextElement.via(ContextToContexts.parent, ContextToContexts.child)
    var fragments by Fragment via FragmentToContexts
}

object ContextToContexts : Table("context_to_contexts") {
    val parent = reference("parent_id", ContextElements)
    val child = reference("child_id", ContextElements)
}

object FragmentToContexts : Table("fragment_to_contexts") {
    val fragment = reference("fragment_id", Fragments).primaryKey(0)
    val contextElement = reference("context_element_id", ContextElements).primaryKey(1)
}

When I try to create a new fragment:

transaction {
    val fragment = Fragment.new(System.currentTimeMillis()) {
        contentText = value
    }
}

then I get the following error message:

java.util.NoSuchElementException: List is empty.
	at kotlin.collections.CollectionsKt___CollectionsKt.last(_Collections.kt:362)
	at org.jetbrains.exposed.sql.statements.BatchInsertStatement.allColumnsInDataSet(BatchInsertStatement.kt:61)
	at org.jetbrains.exposed.sql.statements.BatchInsertStatement.getArguments(BatchInsertStatement.kt:65)
	at org.jetbrains.exposed.sql.statements.InsertStatement.arguments(InsertStatement.kt:148)
	at org.jetbrains.exposed.sql.QueriesKt.batchInsert(Queries.kt:100)
	at org.jetbrains.exposed.sql.QueriesKt.batchInsert$default(Queries.kt:61)
	at org.jetbrains.exposed.dao.EntityCache.flushInserts$exposed_dao(EntityCache.kt:96)
	at org.jetbrains.exposed.dao.EntityCache.flush(EntityCache.kt:53)
	at org.jetbrains.exposed.dao.EntityCache.flush(EntityCache.kt:47)
...

Did I miss anything?

@Tapac Tapac added the bug label Dec 1, 2019
@mpe85
Copy link
Contributor

mpe85 commented Dec 9, 2019

After upgrade from 0.17.7 to 0.19.1 I experience the same error when calling Entity::refresh() (flush=true or flush=false does not matter).

java.util.NoSuchElementException: List is empty.
	at kotlin.collections.CollectionsKt___CollectionsKt.last(_Collections.kt:362)
	at org.jetbrains.exposed.sql.statements.BatchInsertStatement.allColumnsInDataSet(BatchInsertStatement.kt:61)
	at org.jetbrains.exposed.sql.statements.BatchInsertStatement.getArguments(BatchInsertStatement.kt:65)
	at org.jetbrains.exposed.sql.statements.InsertStatement.arguments(InsertStatement.kt:148)
	at org.jetbrains.exposed.sql.QueriesKt.batchInsert(Queries.kt:128)
	at org.jetbrains.exposed.sql.QueriesKt.batchInsert$default(Queries.kt:89)
	at org.jetbrains.exposed.dao.EntityCache.flushInserts$exposed_dao(EntityCache.kt:98)
	at org.jetbrains.exposed.dao.DaoEntityID.invokeOnNoValue(DaoEntityID.kt:9)
	at org.jetbrains.exposed.dao.id.EntityID.getValue(EntityID.kt:8)
	at org.jetbrains.exposed.dao.EntityCache.remove(EntityCache.kt:41)
	at org.jetbrains.exposed.dao.EntityClass.removeFromCache(EntityClass.kt:73)
	at org.jetbrains.exposed.dao.Entity.refresh(Entity.kt:38)

It happens for all entities I call Entity::refresh() on regardless of whether there is a many-to-many relation or not.

@Tapac
Copy link
Contributor

Tapac commented Dec 9, 2019

@matthjes, @mpe85 , could you please file a test with mapping and part where code fails?
I was trying to update ViaTest.kt without any success.

Patch to that test also will be great.

@Tapac
Copy link
Contributor

Tapac commented Dec 10, 2019

It should be fixed in master and released in a few days.

@Tapac Tapac closed this as completed Dec 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants