users@glassfish.java.net

Reacting on EJB3 Create / Delete "Triggers"

From: Markus Karg <karg_at_quipsy.de>
Date: Wed, 19 Aug 2009 12:34:51 +0200

Hello Everybody,

 

in EJB3 an entity was a EnterpriseJavaBean, so in it's ejbCreate, and
ejbRemove methods it could use other entities and technologies. We used
this as some kind of EJB "Trigger":

 

* Using other home interfaces to create more data rows (some kind of
audit log).

* Publishing JMS events on a public blackboard (some kind of
MachineToMachine event pushing).

* Sending JavaMail messages to interested people (some kind of
MachineToMan event pushing).

 

In EJB3 this is no more possible since an EJB3 entity is a POJO but not
a EnterpriseJavaBean anymore. While there still are listeners, those are
POJOs, too, and such cannot access the JNDI context to query for home
interfaces, JMS topics or mail sessions.

 

The good question is: How to solve this is nice way?

 

As there are lots of session beans acting upon the same entity, we do
not see another way than either adding the same "Trigger" code to all of
those session beans, or to create a facade session bean for each entity.
Unfortunately, both solutions are problematic, since an entitiy can also
get removed by a JPA based CASCADE rule, which does not invoke any
facade at all...

 

So how to do that?

 

Thanks

Markus