2 Replies Latest reply on Mar 13, 2005 6:30 PM by Kevin Duncliffe

    EJB CMP/CMR 2.1 to 3.0 migration

    Kevin Duncliffe Newbie

      I'm looking at what might be involved in migrating an existing system based on EJB 2.1 CMP/CMR to EJB 3.0. So far I haven't come across a whole lot of information on the topic, and I thought I'd toss this to the group to see what others are thinking.

      In particular I'm concerned with interoperability -- I'd rather not have to convert all of our EJBs in one go. But many of our entities are highly interdependent -- lots of CMRs.

      I see that interoperability at the session bean level has been defined somewhat in JSR220 Early Draft 2. However, I also see (sec. 9.2.4) that "how the new EJB 3.0 APIs may be used together with the existing EJB APIs...within a single component class" is yet to be defined. Any thoughts as to how that might shake out?



        • 1. Re: EJB CMP/CMR 2.1 to 3.0 migration
          Bill Burke Master

          EJB 2.1 is a very different model than 3.0. Migration steps? Here's some pointers:

          1. Homes/Finders. Turn Home interfaces into Stateless session beans. Finder implementation just turn into queries on the EntityManager. create method implementations turn into session bean methods with new() and EntityManager.persist().

          2. CMR: There is no CMR. Since Entities are POJOs you have to wire them up yourself just as you would any other plain Java object with relationships that wasn't persistent. This is the biggest pain, but if you want POJO persistence, then your persistent objects need to act like POJOs.

          3. EJBQL. EJBQL 3.0 is a superset of EJBQL 2.1. So no issues here.

          You'll find that since Entities are POJOs, even with the extra work of creating DAOs (step 1), you'll find that it simplifies interactions with clients as you don't have to implement the ValueObject pattern.

          Any other concerns?


          • 2. Re: EJB CMP/CMR 2.1 to 3.0 migration
            Kevin Duncliffe Newbie

            My main concern is interoperability. I don't want to migrate our entire system in one go, but the entities in our system are so closely interrelated via CMR, I wonder whether I have any choice.

            Supposing I have a 2.1 Employee entity that has a many-to-one CMR relationship to Company. I'd like to convert both Employee and Company to 3.0, but there is another entity, Customer, that has a many-to-many CMR relationship with Company. I don't want to change Customer right away.

            Can I convert Employee to an Entity POJO without also converting Company and Customer? Or convert only Employee? Should I write a stateless session bean for Company and use that in 3.0-land while retaining home interfaces and CMR for the 2.1 parts of the system and the Customer relationship?

            I'm just not clear on whether I can expect to get the CMR and 3.0 persistence to work on different relationships in the same entity. If I can't, then it seems to me I have to convert every entity in the network of CMR relationships until I have expunged CMR completely. And then our 2.1 to 3.0 migration effort becomes a very long branch, rather than being done in smaller chunks on the main development path. I like smaller chunks.

            That's why section 9.2.4 in JSR220 caught my eye -- it seems like the door is open to forms of interoperability beyond what has already been discussed.

            Or maybe I'm barking up the wrong tree. Whatever the case, I'd be very happy to be set straight.