[jboss-user] [EJB 3.0] - Database triggers

jbeer do-not-reply at jboss.com
Tue Aug 22 12:11:24 EDT 2006


Hi,

I am storing a heirarchical structure in the database using left and right traversal values.  Every time I insert a record into a table, I have a after-insert trigger than fires and updates many records in this table (a number of rows left and right traversal values can change when inserting a new record).

This works fine.  Enter EJB3.  Now this doesn't work fine:  When I persist an entity that affects mutliple rows in the database, I need to refresh all of the entities that were affected by the after-insert trigger in the database.  I don't know the exact entities that will be affected, so it seems like clearing the entity manager might be a good way (albeit expensive) to accomplish this.  Entity callbacks seemed like the way to approach this, using @PostPersist annotation on the entities that get updated.  However, I can't seem to get a hold of the EntityManager (through the bean, injection, or a JNDI lookup).

a) Can you get an EntityManager from an entity callback?

b) Is there a better approach to do this?  I have thought of moving the database triggers into java code in the Entity callback, but since I can't get the EntityManager at this point, that's not a viable option.

Any thoughts and help is appreciated,
Jonathan

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3966742#3966742

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3966742



More information about the jboss-user mailing list