This discussion is archived
2 Replies Latest reply: Jan 11, 2012 10:14 PM by 910542 RSS

MVC- Where is the database layer?

904094 Newbie
Currently Being Moderated
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?
    gimbal2 Guru
    Currently Being Moderated
    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?
    910542 Newbie
    Currently Being Moderated
    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.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points