8 Replies Latest reply on Sep 30, 2004 3:50 AM by ebende

    DAO or EJB

    puneetjains

      Hi
      can any one please tell mewhen to use DAO or EJB
      is the selection also depends on No of hits.
      also are EJB not scalable


      Puneet

        • 1. Re: DAO or EJB
          mittalr

          Hi Puneet,

          DAO is used to interact with database and other type of storages
          where as EJB are your business domain entities. Generally they are used in combination of each other except when you are using CMP type of beans.

          The selection criteria is not based on no. of hits. and EJB's are the way of simplifying and brining a modular type of approach in your design. If they are
          architected properly, then I don't see a reason why they are not scalable. I guess you should read java documentation and try reading Core J2ee patterns and Masering EJB2, that's where I am learning from.

          I hope this helps.

          -Rajesh

          • 2. Re: DAO or EJB

            EJBs are no doubt scalable. Usually you access data using

            1. CMP
            2. BMP
            3. Sessions beans with JDBC.

            Compare it to DAO that can help you to form your own persistence mechanism and policy not only to RDBMS but to any kind of data store. be it XML/file system. But CMP/BMPs can't help you with that as they stick only to RDBMS.

            cant remmeber the link but there was some article related to what you are looking at serverside.com

            • 3. Re: DAO or EJB
              jae77

              DAO is a design pattern that can be followed to encapsulate database access from the rest of your code.

              i tend to use DAOs reguardless of whether or not i am using cmp, straight jdbc, etc just b/c i like to keep that code centralized in one location and it allows me to change the internals w/o affecting multiple source files.

              • 4. Re: DAO or EJB
                imhotep

                Hi Puneet,

                Alternatively, if you want ease of development and neat code (therefore, easy to debug code). You should use:

                1. Vanilla Hibernate
                2. BMP (replace JDBC with Hibernate)
                3.Session Beans with Hibernate

                Trust me, you'll save yourself a lot of trouble steering away from JDBC and CMP beans.

                99% of the time, you don't need to code JDBC, except in certain batch processing scenarios.

                Take the red pill ---> http://www.hibernate.org/

                -Great Imhotep _/"""\_/"""\_/"""\_


                • 5. Re: DAO or EJB
                  sachin_powale

                  I think that when when more objects are created it is better to use DAO else use Entity Bean.
                  For example:

                  When you go for :"Select * from Employee".
                  In this it will create a lot of EJBObjects.
                  Instead of that use DAO.
                  In case of inserting, updating and deleting use Entity Beans.
                  Hope it is right.
                  Sachin

                  • 6. Re: DAO or EJB
                    javabuddy

                     

                    "puneetjains" wrote:
                    Hi
                    can any one please tell mewhen to use DAO or EJB
                    is the selection also depends on No of hits.
                    also are EJB not scalable


                    Puneet


                    • 7. Re: DAO or EJB
                      joydeep

                      As Sachin said, use DAO when the application is primarily of reporting type ( mostly selects). When you require a lot of inserts and updates and real time persistance, also when your java objects need to reflect the state of database objects go for Entity EJBs.

                      Thanks,
                      Joydeep

                      • 8. Re: DAO or EJB
                        ebende

                        Hi,

                        you can find a good story on the pro's and con's on pages 76-80 of "EJB Design Patterns of Floyd Marinescu" free downloadable at
                        http://www.theserverside.com/books/wiley/EJBDesignPatterns/downloadbook.tss

                        Good luck,

                        Evert Bende
                        http://212.203.14.69/topsolar/cgi-bin/climatetop50/cgi-bin/topsites.cgi?action=in&id=69