entitylisteners

@EntityListeners Injection + jUnit Testing

拥有回忆 提交于 2019-12-10 01:47:45
问题 I use @EntityListeners to make operations before I save in my Db and after I load. Inside my Listener class I make a call to an Ecryptor (which needs to fetch info from configuration file), so the encryptor can't be called statically and need to be injected in my Listener. Right? Well, injections in EntityListeners can't be done straight away, but you have some methods to do that, like using SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this); or even the method showed

how to use JPA life-cycle events to get entity data

拟墨画扇 提交于 2019-12-09 10:37:51
问题 I have a RESTful API that makes use of an entity class annotated with @EntityListners. And in the EntityListner.java, I have a method annotated with @PostPersist. So, when that event fires, I want to extract all the information regarding the entity that just got persisted to the database. But when I try to do that, Glassfish is generating an exception and the method in EntityListner class is not executing as expected. Here is the code public class EntityListner { private final static String

@Configurable-Beans not working with JPA-EntityListeners in Spring Boot

↘锁芯ラ 提交于 2019-12-09 03:23:36
问题 I am having a strange problem with a custom jpa-entity listener I've created in a spring boot application. I'm trying to use Springs @Configurable mechanism to configure the EntityListener (as seen in Springs AuditingEntityListener ) but Spring refuses to recognize my Listener as soon as it is used in the @EntityListeners -Annotation on a jpa entity. if it is not configured on a jpa entity, the Listener gets wired/configured by Spring as it should. I've created an example project with a junit

Check whether a JTA transaction is successfully committed

[亡魂溺海] 提交于 2019-12-08 06:46:27
问题 Is there a way to check if the current transaction is committed or not in JPA entity listeners something like the following? @ApplicationScoped public class EntityListener { @Inject private Event<EntityEvent> event; @Inject private EntityManager entityManager; @Resource private UserTransaction userTransaction; @PostPersist @PostUpdate @PostRemove public void onChange(Entity entity) { // This is only a piece of pseudo code. if (userTransaction.isComitted()) { // Do something. } } } Entity

Can you access EntityManagers from EntityListeners?

↘锁芯ラ 提交于 2019-12-07 07:57:49
问题 I'm aware that JSR-000220 Enterprise JavaBeans 3.0 Final Release (persistence) spec states: "In general, portable applications should not invoke EntityManager or Query operations, access other entity instances, or modify relationships in a lifecycle callback method." This appears extremely restrictive. We have a situation in which we would like to access the EntityManager from within an EntityListener. Has anyone come across any adverse effects/pitfulls when using the EntityManager from

Check whether a JTA transaction is successfully committed

倾然丶 夕夏残阳落幕 提交于 2019-12-06 15:56:58
Is there a way to check if the current transaction is committed or not in JPA entity listeners something like the following? @ApplicationScoped public class EntityListener { @Inject private Event<EntityEvent> event; @Inject private EntityManager entityManager; @Resource private UserTransaction userTransaction; @PostPersist @PostUpdate @PostRemove public void onChange(Entity entity) { // This is only a piece of pseudo code. if (userTransaction.isComitted()) { // Do something. } } } Entity listeners in JPA 2.1 are treated as CDI beans that depend upon CDI injection(s) and a transaction context

Can you access EntityManagers from EntityListeners?

☆樱花仙子☆ 提交于 2019-12-05 17:18:06
I'm aware that JSR-000220 Enterprise JavaBeans 3.0 Final Release (persistence) spec states: "In general, portable applications should not invoke EntityManager or Query operations, access other entity instances, or modify relationships in a lifecycle callback method." This appears extremely restrictive. We have a situation in which we would like to access the EntityManager from within an EntityListener. Has anyone come across any adverse effects/pitfulls when using the EntityManager from within a Listener on Jboss/Glassfish, or any other application server for that matter? Arthur Ronald F D

@EntityListeners Injection + jUnit Testing

落爺英雄遲暮 提交于 2019-12-05 01:13:55
I use @EntityListeners to make operations before I save in my Db and after I load. Inside my Listener class I make a call to an Ecryptor (which needs to fetch info from configuration file), so the encryptor can't be called statically and need to be injected in my Listener. Right? Well, injections in EntityListeners can't be done straight away, but you have some methods to do that, like using SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this); or even the method showed here. https://guylabs.ch/2014/02/22/autowiring-pring-beans-in-hibernate-jpa-entity-listeners/ Cool, the

Hibernate JPA Entity listener @Pre and @Post don't work as expected

有些话、适合烂在心里 提交于 2019-12-02 13:26:38
问题 I'm building a real time app and trying to use entity listeners to keep my state up to date. The basic idea is that whenever an area of business logic changes, I re-load the affected entities and reconcile the changes. Here's a MWE: @PrePersist public void PrePersist() { LoggerFactory.logger(App.class).info(" >>> PrePersist count: " + getStars().size()); } @PostPersist public void PostPersist() { LoggerFactory.logger(App.class).info(" >>> PostPersist count: " + getStars().size()); }

JPA @EntityListener does not work as expected

佐手、 提交于 2019-12-02 07:32:21
I am integrating Spring4 and Hibernate5, but there is a problem that I can't resolve. I use @EntityListener annotation on the BaseEntity class that is a super class for other business model. Also I use @MappedSuperclass on the BaseEntity. But it don't work! Use Spring base annotation and run application successfully. Also I inserted a record to db. So I think my configuration of project is current. Any body let me know why? Thanks very much. This is BaseEntity class. @MappedSuperclass @EntityListeners(EntityListener.class) public class BaseEntity implements Serializable { @Id @GeneratedValue