[jboss-user] [EJB 3.0] - Re: How to know when entity is removed?
A_titov82
do-not-reply at jboss.com
Tue Sep 5 14:42:35 EDT 2006
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...
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3969551#3969551
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3969551
More information about the jboss-user
mailing list