How to inject EntityManager in EntityListeners

后端 未结 4 1276
死守一世寂寞
死守一世寂寞 2020-12-06 13:32

I need to inject EntityManager in EntityListener class so that I can perform CRUD operation on it.

POJO:

@Entity
@EntityListner(AuditLogging.class)
c         


        
4条回答
  •  广开言路
    2020-12-06 14:19

    I used a ThreadLocal to pass the Spring Application Context which contains EntityManager around. Though I am not sure if it is safe Is it safe to pass in the Spring Application Context into a ThreadLocal associated with a request? but so far it is working for me.

提交回复
热议问题