Discussions

EJB design: how to: EJB + PojoDao + transaction?

  1. how to: EJB + PojoDao + transaction? (3 messages)

    If I have a CMT method in a stateless session bean public class MySLSB .... { cmtMethod() { dao1.save(foo); dao2.save(bar); } } where both dao1 and dao2 are POJOs. When dao2.save(bar) fails, dao1.save(foo) cannot be rolled back because it's a POJO, correct? If that is the case, what is the good way to do transaction here? I don't like the idea of implementing both DAOs as EJBs. Is that the only choice here? Thanks, Ric
  2. I think in this type of a scenario the only option left to you is to use Bean Managed Transaction and in the beginning of the method in Session Bean get the UserTransaction from SessionContext and call its begin method and in case of any exception call its rollback method . This should solve your problem. Hope this helps. Cheers Deb
  3. Once you are inside ejb tier the transaction will work. So under the given scenarios if you are obtaiing the connection from TXDataSources then transaction intigrity is maintained.
  4. Re: how to: EJB + PojoDao + transaction?[ Go to top ]

    Once you are inside ejb tier the transaction will work.
    So under the given scenarios if you are obtaiing the connection from TXDataSources then transaction intigrity is maintained.
    I see. Thanks, that's a relief. Seems I don't need to do anything extra other than declare the method to be CMT. One step further: I assume the CMT will for sure work if I look up my transaction resources (datasources -> connections) via JNDI from the container; but would it still work if I obtain the DB connections by Class.forName() in one or both of the POJO DAOs? Cheers, Ric