Question

I've created a sample application based on the JBoss Kitchensink example. This application records Entities using CDI Beans. I've found quite easy to store a new Entities using JPA + firing the Observer on the newly created Entity:

@Inject
private Event<MyEntity> propEventSrc;

public void put(MyEntity p){

      em.persist(p);
      propEventSrc.fire(p);
}

However I cannot find a way to fire the event in case the user wants to delete all records. In other words:
public void delete(){

    Query query = em.createQuery("delete FROM MyEntity ");

    query.executeUpdate();

        // I need to fire an event here so that the List of MyEntities from the Producer class gets updated           
}

I've tried with the notifyAll() method of the propEventSrc but that does just produce Exceptions, Any idea how to solve this issue ?
Thanks Max

Was it helpful?

Solution

if you want to fire event for every entity that gets deleted, best approach would be to add @PostRemove handler to entity in question and add code that fires event.

some examples http://en.wikibooks.org/wiki/Java_Persistence/Advanced_Topics

you might have some problems with injecting CDI objects into EntityListener but you can workaround this(until JPA 2.1) as described in CDI injection in EntityListeners

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top