实体的元数据未定义
Metadata for entity is undefined
我正在尝试将两个实体与 n:m
关系、乐队和事件联系起来。当一个事件被移除时,乐队应该保留。但是,作为活动的一部分,乐队可能不会被移除。
附加的测试用例失败并显示以下日志:
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
问题似乎是缺少实体元数据,但我找不到任何相关文档或类似问题。有人知道解决方法吗?
实体
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(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()
}
}
您需要在 XdModel 中注册此类型,然后传播此类型以存储:
XdModel.registerNodes(XdBand, XdEvent)
initMetaData(XdModel.hierarchy, store)
您可以使用 XdModel#scanPackages
或 XdModel#scanJavaClasspath
方法来查找所有可用类型,而不是 XdModel#registerNodes
方法。
我正在尝试将两个实体与 n:m
关系、乐队和事件联系起来。当一个事件被移除时,乐队应该保留。但是,作为活动的一部分,乐队可能不会被移除。
附加的测试用例失败并显示以下日志:
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
问题似乎是缺少实体元数据,但我找不到任何相关文档或类似问题。有人知道解决方法吗?
实体
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(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()
}
}
您需要在 XdModel 中注册此类型,然后传播此类型以存储:
XdModel.registerNodes(XdBand, XdEvent)
initMetaData(XdModel.hierarchy, store)
您可以使用 XdModel#scanPackages
或 XdModel#scanJavaClasspath
方法来查找所有可用类型,而不是 XdModel#registerNodes
方法。