entitylisteners

JPA 2.1 Create entity within JPA EntityListener

你说的曾经没有我的故事 提交于 2021-01-28 14:54:45
问题 I try to create a log entry as soon as one of my entities got changed or created. In order to do this, I registered an EntityListener on an AbstractEntity class. AbstractEntity has a List of LogEntries and the cascade type of this list is ALL (all of my entities inherits from AbstractEntity). Current implementation of my EntityListener: public class EntityChangeListener { @Inject SessionController sessionController; @PreUpdate public void preUpdate(AbstractEntity entity) { createLogEntryFor

JPA 2.1 Create entity within JPA EntityListener

百般思念 提交于 2021-01-28 14:42:56
问题 I try to create a log entry as soon as one of my entities got changed or created. In order to do this, I registered an EntityListener on an AbstractEntity class. AbstractEntity has a List of LogEntries and the cascade type of this list is ALL (all of my entities inherits from AbstractEntity). Current implementation of my EntityListener: public class EntityChangeListener { @Inject SessionController sessionController; @PreUpdate public void preUpdate(AbstractEntity entity) { createLogEntryFor

How can I use an EJB in a EntityListener?

微笑、不失礼 提交于 2020-06-16 17:38:06
问题 I'm designing my database and I reached the situation that an Entity itself requires to access database. I read Why sometimes a reference to an EntityManager inside JPA entities is needed. And I'm curious about the possibility of accessing an EJB in EntityListener. public class MyEntityListener { @PrePersist private void onPrePersist(final Object object) { // find an EJB // and set those required values // which each resides in a specific table. } } Is this possible or (or and) preferred? 回答1

Does @EntityListener works with @MappedSuperclass as well?

余生颓废 提交于 2020-01-24 03:39:08
问题 Folks! If I define an Entity Class and annotate it with @MappedSuperclass and an @EntityListener , does the listener also get called for lifecycle events within a child class? Example: @MappedSuperclass @EntityListeners(class=LastUpdateListener.class) public abstract class Animal { @Id private Integer id; private String name; private Calendar dateOfBirth; @Transient private int age; private Date lastUpdate; //getters and setters /** * Set my transient property at load time based on a

JPA @EntityListener does not work as expected

点点圈 提交于 2020-01-11 13:27:10
问题 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

Modify entity with EntityListener on cascade

大兔子大兔子 提交于 2020-01-05 05:18:51
问题 I have a database in which an entity (say, User) has a list of entities (say, List). As a requirement, I must have a denormalized count of the entities on the list: @Entity class User { /* ... */ @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) private List<Friendship> friends; public int friendsCount; /* ... */ } When I add a new element to the list, I must, transactionally, increase the corresponding counter. I tried to do so using an EntityListener: class

Field values are not being modified on PreUpdate callback

故事扮演 提交于 2019-12-24 12:34:09
问题 I've defined the following class as as default Entity Listener, so every time I call the persist() or merge() methods this code will be executed automatically: public class StringProcessorListener { @PrePersist @PreUpdate public void formatStrings(Object object) { try { for (Field f : object.getClass().getDeclaredFields()) { if (f.getType().equals(String.class)) { f.setAccessible(true); if (f.get(object) != null) { f.set(object, f.get(object).toString().toUpperCase()); } } } } catch

org.jboss.weld.exceptions.IllegalArgumentException: WELD-001456: Argument resolvedBean must not be null

懵懂的女人 提交于 2019-12-23 12:29:10
问题 Injecting EJBs into entity listeners is available, since JPA 2.1. WildFly 9.0.2 final however, fails with the following exception. 15:41:12,125 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 149) MSC000001: Failed to start service jboss.persistenceunit."Test.ear/Test-ejb.jar#Test-ejbPU": org.jboss.msc.service.StartException in service jboss.persistenceunit."Test.ear/Test-ejb.jar#Test-ejbPU": javax.persistence.PersistenceException: [PersistenceUnit: Test-ejbPU] Unable to

JPA EventListener method not called on change to many-to-many collection?

自闭症网瘾萝莉.ら 提交于 2019-12-17 16:53:08
问题 I am using JPA with Hibernate as the implementation in my Spring webapp. I use EntityListener s for auditing (Spring-data) and other notification purposes. In general it works fine. However, when changes are made to a many-to-many collection/relationship, without any other change to any field of the entities themselves , the @PostUpdate event of the EventListener s are not fired. To give a concrete example : I have a User and a Role entities, with a many-to-many relationship between them,

Hibernate 4 JPA EntityListeners not firing in Spring MVC/ Spring Data application

情到浓时终转凉″ 提交于 2019-12-12 06:38:51
问题 I've got a Hibernate 4 / Spring MVC 3.2.4/ Spring Data 1.4.1 with Spring Security application in which I am trying to integrate EventListeners on my entity classes. I think I have everything configured properly, and when I run my unit tests, I can see my event listeners being fired. However, when i run my full MVC application, the event listeners are never fired. I'm a bit lost where/how to debug this problem. My EntityManagerFactory is setup pretty much the same in both cases: PRODUCTION: