views:

46

answers:

1
+1  Q: 

Design question

Hi everbody,

We are building software in java, and are new to it. I confused about JPA. Normally in MVC pattern, SQL queries are hidden in model. And controller can't access the db directly.

When I use JPA, should model retrieve JPA object to controller? If yes, then controller has access to db, and this is against to pattern?

+3  A: 

JPA is just an abstraction between your Domain Model Object and SQL (your JPA implementation like Hibernate etc. creates all the SQL queries for you).

The controller will not even know which database JPA uses at all. If you want a simpler application architecture your controller can use the JPA features directly. Other architecture use a Data Acces Object layer (where these objects provide methods like List getAllThingsBetween(Date from, Date to)) between your controller and JPA, so that the controller won't even know, that you are using JPA.

Daff
thank you.now i have a clue where to start :)
qasanov