entitylisteners

Can you access EntityManagers from EntityListeners?

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 w...

JPA entitylisteners and @embeddable

I have a class hierarchy of JPA entities that all inherit from a BaseEntity class: @MappedSuperclass @EntityListeners( { ValidatorListener.class }) public abstract class BaseEntity implements Serializable { // other stuff } I want all entities that implement a given interface to be validated automatically on persist and/or update....

Injecting into Validator or EntityListener?

I'm trying to do some validation of complex constraints on Hibernate entities in a JBoss JEE system. For that purpose, I need my validator (whether it be an actual JSR303 validator or just an EntityListener for PrePersist/PreUpdate/PreRemove) to have access to my DAO beans. Much perusal of JSR303 stuff doesn't give me any indication that...

Modify entity with EntityListener on cascade

Hello. 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 friendsCou...

Using Hibernate/JPA Event Listener to update one entity when other entities are updated.

Hi, I have three entities in my system - one of which must be updated when fields on the other two are changed: @Entity public class Order { private String name; private Integer quantity; private String status; } @Entity public class OrderLocation { private String status; private String desc; } @Entity public cla...