-
1. Re: MDB initialized too early?
pmuir Nov 19, 2007 5:23 AM (in response to svadu)Post your MDB and SLSB
-
2. Re: MDB initialized too early?
svadu Nov 19, 2007 5:51 AM (in response to svadu)Thanks for the quick response! Here are the sources (I had to 'censor' it for obvious reasons):
MDB:@MessageDriven(name = "Processor", activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "myqueue"), @ActivationConfigProperty(propertyName = "providerAdapterJNDI", propertyValue="java:/TIBCOJMSProvider") }) public class Receiver implements MessageListener { @Resource private MessageDrivenContext context; /** * Controller does the actual processing * of the incoming message */ @EJB private Creator creator; /** * @see javax.jms.MessageListener#onMessage(javax.jms.Message) */ public void onMessage(Message msg) { try { TextMessage txtMsg = (TextMessage)msg; String text = txtMsg.getText(); creator.process(text); } catch (JMSException e) { e.printStackTrace(); context.setRollbackOnly(); } catch (ValidationException e) { e.printStackTrace(); context.setRollbackOnly(); } } /** * @param creator the controller to set */ public void setCreator(Creator creator) { this.creator = creator; } /** * @param context the context to set */ public void setContext(MessageDrivenContext context) { this.context = context; } }
SLSB Local interface:@Local public interface Creator { /** * Processed an incoming message bus from a message bus * and stores it in database. * * @param text * @throws ValidationException * @return an instance of saved entity */ public Entiteit process(String text) throws ValidationException; /** * Sets entity manager * @param em */ public void setDatabase(EntityManager em); /** * Retrieves entity manager * @return entity manager instance */ public EntityManager getDatabase(); }
SLSB itself:/** * Processes entities * */ @Stateless @Name("Creator") public class CreatorBean implements Creator { private EntityManager em; /** * Sets entity manager * @param em */ @PersistenceContext public void setDatabase(EntityManager em){ this.em = em; } /** * Retrieves entity manager * @return entity manager instance */ public EntityManager getDatabase() { return this.em; } /** * Processes the entities from xml and stores it in database. * It also performs checking on existing records end replaces them if found. * @throws ValidationException */ public Entiteit process(String xmlText) throws ValidationException { Entiteit en = null; try { IBindingFactory bfact = BindingDirectory.getFactory(Entiteit.class); IUnmarshallingContext uctx = bfact.createUnmarshallingContext(); StringReader sr = new StringReader(xmlText); en = (Entiteit) uctx.unmarshalDocument( sr, null); em.persist(en); } catch (JiBXException e) { throw new ValidationException("Error processing incoming entity", e); } return en; } }
-
3. Re: MDB initialized too early?
svadu Nov 20, 2007 4:46 PM (in response to svadu)Is there a problem with the way I use it or should I create a JIRA issue?
-
4. Re: MDB initialized too early?
obfuscator Nov 27, 2007 8:59 AM (in response to svadu)We are seeing this aswell. This particular problem also has one big implication: Since seam uses its own entity manager, and this affects caching etc, we have decided to use the seam managed entity manager in all DAO:s. Therefore, it is critical that seam is initialized before any component of the application is triggered. It seems like seam dependencies spread just like const-correctness :D
Is there any other solution then to wait for seam to initialize in onMessage? This seems to work, but is a big hazzle, considering transaction timeouts etc.
Regards -
5. Re: MDB initialized too early?
svadu Nov 27, 2007 4:39 PM (in response to svadu)Created a JIRA issue: http://jira.jboss.com/jira/browse/JBSEAM-2286