6 Replies Latest reply on Sep 1, 2001 3:01 PM by rakhbari

    CMP vs. BMP

    twilight

      I've been using CMP most of the time while learning EJB, but I just read the discussion of container-managed persistence in the documentations (http://www.jboss.org/documentation/HTML/ch04s11.html) which made me give it a second thought. Can CMP really be that inefficent as the document states? As BMP isn't that much harder to implement, maybe it's worth the effort?

      Regards,
      \Anders

        • 1. Re: CMP vs. BMP
          camtabor

          I am also interested in hearing some other opinions on this issue. I use CMP whenever I can, just to avoid writing the sql, a CMP bean is easier to maintain simply because there is less code. But if performance is severely sacrificed, maybe BMP is the way to go.

          • 2. Re: CMP vs. BMP
            haytona

            Using JAWS managed persistance can overcome some of these efficiency limitations especially by using custom finder methods. (See here: http://www.jboss.org/documentation/HTML/ch05s07.html for more info)

            However there are limitations to custom finders that are quite fustrating. There is [currently] no way of performing wildcard sql queries (* and %) with a parameter first. (See http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/ for more info)
            Hopefully this will be rectified in a future release.

            • 3. Re: CMP vs. BMP
              davidjencks

              I don't think the poster you quoted looked very hard at the sql. * and % are not keywords, they need to be in a quoted literal string.

              mycolumn like {0}||'%'

              is more likely to generate acceptable sql.

              • 4. Re: CMP vs. BMP
                haytona

                Hi,

                I've spent a few hours this morning trying to work it out. I'm using JBoss 2.4.0_26 with integrated Tomcat on Windows 2000 Pro. I am currently using the built-in databases (InstantDB I think as I'm using the JAWS persistance manager).

                I have converted the CD collection example into a simple phone list and have a PhoneEntryEJB and a PhoneListEJB. I am acessing them through a jsp based web tier.

                Extract from JAWS.xml:

                findByLastNameBeginning
                lastName = {0}"%" IGNORE CASE
                lastName, firstName
                <read-ahead>true</read-ahead>


                findByLastName
                lastName like {0} IGNORE CASE
                lastName, firstName
                <read-ahead>true</read-ahead>



                Extract from PhoneEntryHome.java:
                public Collection findByLastNameBeginning(String searchTerm) throws RemoteException, FinderException;

                When calling this finder method through the jsp bean through the session bean I get the following error if I use "b" as the search term.

                Error in JBoss console:
                [Default] Thread-14 SELECT PhoneEntryEJB . id , lastName , firstName FROM PhoneEntryEJB where lastName = b % IGNORE CASE ORDER BY lastName , firstName
                [Default] Thread-14 SELECT PhoneEntryEJB.id, lastName, firstName FROM PhoneEntryEJB where lastName = ?"%" IGNORE CASE ORDER BY lastName, firstName
                Don't understand SQL after: "%"
                Expected: "(" found: "%"
                [Default] javax.ejb.FinderException: Find failed

                BUT if I use the findByLastName method and pass "b%" as the searchTerm then it works as I would expect the other finder method to work. I don't really want to have to manipluate the string before using the finder method as that sort of defeats the purpose. I've tried many different combinations of {0}"%" "{0}%" etc all to no avail.

                Any suggestions would be much appreciated.

                Hamish Carpenter

                • 5. Re: CMP vs. BMP

                  BMP vs CMP is a tough question.

                  I've done quite a bit of both and what people regard as the strengths and weaknesses of both are mostly correct (maintenance/portability/developer productivity/..). I have some very CPU/IO intensive use cases in my current project and they work very fast using std JAWS cmp. I have the commit-option set to 'A' and tuned-updates which no doubt helps.

                  Another thing to consider is that when EJB 2.0 rules the world containers will be able to cache CMP bean state much more aggressively and CMP code may actually become faster.

                  My biggest complaint with doing BMP is the endless silly SQL syntax errors that you get. I spent several years doing plain old database development with stored procedures, embedded SQL in C and 4GLs on several database engines and I get the syntax wrong! IMHO One of the big selling points of EJB is that you don't need to be a SQL nut to use them effectivley.

                  I don't know if this helps.

                  • 6. Re: CMP vs. BMP
                    rakhbari

                    I've been in the software industry for the past 14 yeras, done projects on anything form IBM 3090 mainframes to HP minis. I've therefore also spent a lot of time coding SQL everywhere and agree that it's bogus to write, maintain, what have you when it comes to an OO environment.

                    But with a good and fairly basic XML-driven O/R mapping layer BMP can be made a hell of a lot easier. All you need is a single persitence class which all your BMP entity beans subclass from and your EBs have to do is define to the super-class their schema via some well-formed XML. I realize that JAWS takes care of a lot of this for you but my point is that with what I describe above (which is not trivial to write, I might add) you could have the best of both worlds: The complete control of BMP, AND the ease of use of CMP. As a matter of fact that's how I'm planning on proceding for implementing a system for a client under JBoss.

                    Another thing with CMP that I have not seen is how do you specify Foreign Keys to other tables and multiple-compound indexes in the CMP defition for the bean?

                    -RA-