Announcement Announcement Module
No announcement yet.
Questions about ejbtest app in autobuilds Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Questions about ejbtest app in autobuilds

    I posted this to the Spring User Mailing List, but got no responses. I'm hoping posting it here will hopefully generate something:

    I think these questions are mostly targeted at Colin since I think he
    wrote the ejbtest app, but feel free to provide answers if you have them.

    I've been battling with our app config for a few days trying to get
    our Message Driven Beans to deploy with JBoss (everything works fine
    with Weblogic). The way we have our app setup is most of the code
    (including the files that define our Spring context ) in one jar. That
    jar is shared by our webapp and our ejb jar inside an EAR. The webapp
    deploys fine and the ContextLoaderListener there fires up our Spring
    context and it wires up the JtaTransactionManager which we use in
    conjunction with the TransactionProxyFactoryBean to do transaction
    declarations on our services. These services are backed by DAOs backed
    by Hibernate. The web part of our app runs fine, transactions occur
    like they should.

    The problem comes up when we send a message to one of our MDBs. It's
    at that point that ejbCreate() gets called and since we are using
    AbstractJmsMessageDrivenBean defined to use our application's context
    definition file, it starts to create a bean factory for the Message
    Driven Bean to use that contains all the beans our web app uses. We
    get an exception when the JtaTransactionManager tries to find the
    UserTransaction object at java:/comp/UserTransaction because JBoss
    doesn't have one there for EJB modules.

    While searching around for a solution to this problem I ran across a
    post by Colin in the forums mentioning the ejbtest app in CVS that
    uses EJBs with a service layer backed by both ContainerManaged and
    Spring managed transactions. I was intrigued.

    First thing I really like was that the Web app and the EJB layer share
    the same Application context. That definitely seems like a more
    efficient solution. It also explains why the app deploys on JBoss
    since the JtaTransactionManager is only initialized when the Web App
    does and is available later from the same bean factory the EJBs get to
    use. I also noticed that the HibernateSessionFactory definition goes
    ahead and defines the JBoss Jta lookup.

    So, first, it appears this solution only works (at least on JBoss) if
    the EJBs are deployed in the same EAR as the web app. How would you go
    about using this if you wanted to deploy just the EJB part on a remote
    server? The JtaManager would no longer be able to lookup the
    UserTransaction at the same location on JBosss. I guess you could
    configure that location in that case, but we are trying to create a
    Jar that doesn't need to be changed for any deployment, is that an
    achievable goal?

    Second, I'm guessing the JtaTransactionManager is smart enough to know
    when a CMT transaction is already going on and join it for the
    TransactionProxyFactoryBean created services? As well as hibernate
    knowing when to delegate the transaction management to Jta. But does
    that mean for an Message Driven bean the transaction starts for the
    call of the onMessage() and I would have to commit manually between
    service method calls if I lookup service beans from the context and
    call their methods and want their actions to commit?

    I definitely think I am going to change our deployment to share the
    factory since most of the time the MDBs will be co-located with the
    web app. But I still want to solve the problem of being able to deploy
    the same core jar in a standalone setting with just the MDBs and no


  • #2
    And the reply I posted on the mailing myself:

    Thinking about this further, I thought, hey, there's a bean here that
    says it's Not CMT and has Spring Transactions. That's the case that
    would do what I want since I want the services to dictate the
    transactions. But while checking that out, I noticed the
    <transaction-type> defined for SimpleWithNoCmtAndSpringTx is
    "Container", is that correct? Shouldn't it be "Bean"?