2 Replies Latest reply on Jan 12, 2012 6:14 AM by 910542

    MVC- Where is the database layer?

      In MVC, M is the model, V is the view and C is the controller. But whatever projects I have made till now, I have a separate layer called data layer where I do all the database operations. In MVC, are we saying that the database operations are within the controller layer? That's quite a little mismatch! Separation of layers yet merge of controller & database operations!!

      PS: Apologize, I couldn't find any relevant place to put this question...
        • 1. Re: MVC- Where is the database layer?
          MVC pattern assumes that you want to separate business logic and view logic - the business logic would happen in the controller classes. Database operations are part of business logic, so they too would happen in the controller classes too. It isn't that difficult really.

          You should try to keep high level concepts (MVC) and low level concepts (database operations) separate to avoid confusion.
          • 2. Re: MVC- Where is the database layer?
            You can actually use MVC implementations and persist directly to a database. Depending the project requirements, and for seperation of concerns, it is dough better to provide a different layer in your business logic handling persistency related concerns.

            Many tutorials on the web provide a straight way to persist data to a database from within your MVC, but when you're handling with a big project, you should better your JPA in your business layer and provide a facade on your entity which you can access from your MVC (front) implementation.