-
1. Re: How to know when entity is removed?
alrubinger Sep 4, 2006 11:37 AM (in response to a_titov82)The lifecycle methods in EJB3 are defined through annotations - looks like you'd like @PostRemove.
http://trailblazer.demo.jboss.com/EJB3Trail/persistence/entitylifecycle/index.html
S,
ALR -
2. Re: How to know when entity is removed?
a_titov82 Sep 4, 2006 1:04 PM (in response to a_titov82)The lifecycle methods in EJB3 are defined through annotations - looks like you'd like @PostRemove.
But how can I send JMS messages in this method? I think I cannot use neither EntityManager nor local interfaces inside entity (like in EJB 2.x)... Or I can? -
3. Re: How to know when entity is removed?
alrubinger Sep 5, 2006 10:58 AM (in response to a_titov82)Hmm...never tried throwing an EntityManager into an entity itself - probably not the best practice. I don't remember reading anything prohibiting that injection...But why do you need it do send JMS?
First solution that occurs to me would be to separate your listeners from the entity using @EntityListener. From that externalized class you can either send your JMS messages or delegate out to a Session bean to do it for you...
S,
ALR -
4. Re: How to know when entity is removed?
a_titov82 Sep 5, 2006 2:42 PM (in response to a_titov82)Well perhaps, I really do not need to throw an EntityManager to send JMS. But I would like to use local beans (because they work faster) in entity listener.
I need JMS (or some thing like this) to notify remote clients when something happens with entity (insert, update or remove). So, I have to code this logic in life cycle methods.
After some researches I found the way to do that.@EntityListeners(EntityListener.class) public class RelatedEntity implements Serializable { ... } public class EntityListener{ @PostLoad public void onLoad(Object obj){ try { InitialContext ctx=new InitialContext(); EntityLocalHome localHome=(EntityLocalHome) ctx.lookup("Entity1Home/local"); localHome.onLoad(obj); } catch (NamingException e) { e.printStackTrace(); } } public EntityListener() { System.out.println("Creating entity listener"); } }
May be there is a way to do it better (and more elegant)?
I was disappointed, that I could not use dependency injection here (instead of lookup). But it works.
There is only one thing, that confuses me. Why the constructor of the EntityListener is never invoked?
I think that EJB 3.0 is not designed for remote clients, only for web interfaces... -
5. Re: How to know when entity is removed?
a_titov82 Sep 5, 2006 3:20 PM (in response to a_titov82)About the constructor... I understood, that it is invoked on deployment.