Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 未调用实体侦听器_Hibernate_Jpa_Kotlin_Micronaut_Micronaut Data - Fatal编程技术网

Hibernate 未调用实体侦听器

Hibernate 未调用实体侦听器,hibernate,jpa,kotlin,micronaut,micronaut-data,Hibernate,Jpa,Kotlin,Micronaut,Micronaut Data,我有以下实体和关联的侦听器 @Entity @EntityListeners(InjuryListener::class) class Injury(val description: String, @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) val id: Long = 0) @Singleton class InjuryListener : PreDeleteEventListener {

我有以下实体和关联的侦听器

@Entity
@EntityListeners(InjuryListener::class)
class Injury(val description: String,
             @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) val id: Long = 0)

@Singleton
class InjuryListener : PreDeleteEventListener {
    @PreRemove
    fun preRemove(injury: Injury) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onPreDelete(event: PreDeleteEvent?): Boolean {
        val injury = event?.entity as Injury
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }
}

然而,当我删除一个伤害时,我的InjuryListener上的两个方法都不会被调用。关于这是为什么的任何线索?

只要您在micronaut世界,大多数“魔法”都是在编译时完成的。micronaut数据的一个主要声明是不存在运行时元模型

这实际上意味着实体上没有
EntityListener
注释


在micronaut world中,您应该使用
DataInterceptor
来实现所需的功能

只要您身处micronaut世界,大多数“魔法”都是在编译时完成的。micronaut数据的一个主要声明是不存在运行时元模型

这实际上意味着实体上没有
EntityListener
注释


在micronaut world中,您应该使用
DataInterceptor
来实现所需的功能

正如Ilya Dyoshin所写的
@EntityListener
@PreRemove
不用于Micronaut数据。但是你可以通过AOP技术来解决它

首先,使用您需要的预删除逻辑创建您自己的拦截器:

@Singleton
class InjuryPreDeleteInterceptor : MethodInterceptor<Injury, Boolean> {
    override fun intercept(context: MethodInvocationContext<Injury, Boolean>): Boolean {
        val injury = context.parameterValues[0] as Injury
        if (injury.someFlag) {
            // do not delete
        } else {
            // delete
            context.proceed()
        }
        return true
    }
}
并将先前创建的
@VisitInjuryDelete
注释注释的
delete()
方法签名添加到
InjuryRepository
界面:

@VisitInjuryDelete
override fun delete(Injury entity)

您可以在此处找到有关Micronaut中AOP的更多信息:

正如Ilya Dyoshin所写的
@EntityListener
@PreRemove
不用于Micronaut数据。但是你可以通过AOP技术来解决它

首先,使用您需要的预删除逻辑创建您自己的拦截器:

@Singleton
class InjuryPreDeleteInterceptor : MethodInterceptor<Injury, Boolean> {
    override fun intercept(context: MethodInvocationContext<Injury, Boolean>): Boolean {
        val injury = context.parameterValues[0] as Injury
        if (injury.someFlag) {
            // do not delete
        } else {
            // delete
            context.proceed()
        }
        return true
    }
}
并将先前创建的
@VisitInjuryDelete
注释注释的
delete()
方法签名添加到
InjuryRepository
界面:

@VisitInjuryDelete
override fun delete(Injury entity)

您可以在Micronaut中找到有关AOP的更多信息:

如何删除实体?通过定义为“@repository interface InjuryRepository:crudepository”的我的存储库如何删除实体?通过定义为“@repository interface InjuryRepository:crudepository”的我的存储库您是否有一个示例或可能的链接?我在谷歌上找不到太多,你有没有一个例子或可能的链接?我在谷歌上找不到什么