Announcement Announcement Module
Collapse
No announcement yet.
Big DAO beans or a lot of small DAO beans? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Big DAO beans or a lot of small DAO beans?

    Which one is better?

  • #2
    In our company practice, 1 DAO usually pointing to 1 table in database.

    so if there is a lot different query / insert statement, so the DAO will become big

    Comment


    • #3
      I think it depends what makes more sense. How big does your DAO actually get? I think the biggest one we have is 600 ish lines, not really that bad. As long as it's dealing with one job it should be ok.
      Last edited by karldmoore; Aug 27th, 2007, 04:08 PM.

      Comment


      • #4
        hi, here i ask about the effect on performance, or else big or small is really

        not important.

        Comment


        • #5
          Originally posted by Rucent View Post
          Which one is better?
          What does good OO tell you

          "Each thing should do one thing and one thing well" and "anything should be implemented in one place and one place only" leads me to believe that one DAO per logical entity (*not* DB table ) is the way to go.

          Comment


          • #6
            leads me to believe that one DAO per logical entity (*not* DB table ) is the way to go.
            litle confuse

            Hibernate entity class is a representation of a db table right???

            Comment


            • #7
              Originally posted by dr_pompeii View Post
              Hibernate entity class is a representation of a db table right???
              Not necessarily. That's what an O2R mapper is about.

              Joerg

              Comment


              • #8
                hello Jörg

                thanks for the reply

                That's what an O2R mapper is about.
                yes, if i dont bad remember Hibernate is a ORM tool

                thanks

                Comment


                • #9
                  Originally posted by dr_pompeii View Post
                  litle confuse

                  Hibernate entity class is a representation of a db table right???

                  It is perfectly feasible to map a single java Class to multiple tables, and vica versa in Hibernate. One DAO per class would seem to be a sensible strategy. One DAO per table would be breaking the contract of what DAOs are all about. It would essentially be an implementation leak of your schema.

                  Comment


                  • #10
                    hello yatesco
                    One DAO per class would seem to be a sensible strategy.
                    i am confuse now

                    if this right?

                    a table db call ,mmm, Order , so it should has OrderDAO (CRUD operations) , and this OrderBO

                    i saw this approach in Pro Spring if i dont bad remember

                    now about of inheritance , class Person and 2 subclasses, Client and Worker ,
                    yes both classes are 1 table in the db (discrimantor in the hbm mapping)

                    but each class has a DAO and BO classes, it is right?

                    regards and thanks for advanced for the explanation

                    Comment


                    • #11
                      It is dangerous to talk about specifics too much because obviously every situation is different.

                      However, in general, if I have an Order class (regardless of how many tables there were) then yes, I would have an OrderDAO. If I have a Person (which is extended by Employer and Employee) then I would probably have a PersonDAO.

                      I wouldn't necessarily say the same thing about the service layer (or Business Objects). Creating a PersonService and OrderService may be the right thing to do, but then again it might not be needed.

                      It is worth taking a step back here: the BO/Service is responsible for implementing use cases, and therefore the methods should be use case orientated. The DAOs/Repositories OTOH are responsible for persisting/retrieving entities.

                      So yes, one DAO per entity hierarchy (i.e. PersonDAO *not* PersonDAO, EmployeeDAO) but maybe not one Service per entity.

                      Comment


                      • #12
                        thanks yatesco for the explanation

                        i appreciate the theory

                        regards

                        Comment

                        Working...
                        X