Search code examples
xodusxodus-dnq

Metadata for entity is undefined


I'm trying to connect two entities with an n:m relationship, bands and events. When an event is removed, the band should remain. The band may not be removed while part of an event however.

The attached test case fails with the following log:

    2020-03-02 21:54:32.583 [Test worker] DEBUG c.j.t.dnq.database.ConstraintsUtil - Cannot check links cardinality for entity XdEvent: id = 0-0. Entity metadata for its type [XdEvent] is undefined
    2020-03-02 21:54:32.583 [Test worker] DEBUG c.j.t.dnq.database.ConstraintsUtil - Cannot check links cardinality for entity XdBand: id = 1-0. Entity metadata for its type [XdBand] is undefined

It seems the issue is missing entity metadata but I cannot find any related documentation or similar issues. Does anyone know a fix?


Entites

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

    var name by xdRequiredStringProp(unique = true)
    var image by xdBlobProp()
    val events: XdMutableQuery<XdEvent> by xdLink0_N(XdEvent::bands, onDelete = OnDeletePolicy.FAIL)
}
class XdEvent(entity: Entity) : XdEntity(entity) {
    companion object : XdNaturalEntityType<XdEvent>()

    var date by xdRequiredDateTimeProp()
    /**
     * Milliseconds since midnight
     */
    var startTime by xdIntProp()
    /**
     * Milliseconds since midnight
     */
    var endTime by xdIntProp()
    val bands : XdMutableQuery<XdBand> by xdLink1_N(XdBand::events, onDelete = OnDeletePolicy.CLEAR)
}

Test Case

@Test(expected = ConstraintsValidationException::class)
fun testCannotRemoveBandWithEvent() {
    val bandName = "Some Band"
    Database.store.transactional {
        val event = XdEvent.new {
            date = LocalDate.now().toDateTime(LocalTime.MIDNIGHT)
            startTime = 0
            endTime = 0
        }
        XdBand.new {
            name = bandName
            events.add(event)
        }
    }

    Database.store.transactional {
        XdBand.all().first().delete()
    }
}

Solution

  • You need to register this types in XdModel and then propagate this types to store:

            XdModel.registerNodes(XdBand, XdEvent)
            initMetaData(XdModel.hierarchy, store)
    

    Instead of XdModel#registerNodes method you can use XdModel#scanPackages or XdModel#scanJavaClasspath methods to find all available types.