I'm currently writing my diploma thesis and I'm stuck at the Database Communication topic. My problem is not the implementation, but rather the architecture behind JSF
. I read a lot about it, but don't really get it.
All my Database accesses are contained in the EJB
project, and are handled with JDBC. JPA does the mapping between the DB-Entities and the Objects. So JDBC
is just the driver which connects to the DB?
Thanks in advance!
JSF is in no way connected to database management, though the latter is typically always used in a JSF application.
Though all the job can be done with 'plain JDBC', it is more appropriately done using the Java Persistence API, or JPA. In the latter case, the JPA provider uses 'plain JDBC' under the covers.
Think of that relation in a following manner: (raw) JDBC is to JPA just like (raw) Servlet is to JSF.
The architecture of the project must be well organized according to principle "low coupling and high cohesion"
The system layers should be well seperated. The basic architecture have 3 layers.
- Presentation Tier: JSF managed beans are in this layer. The task of this layer is to correspond user actions, hold user data and show the data to the user. Basically, its responsibility is bounded by MVC pattern regardless of which implementation you use (JSF, Spring MVC or Struts)
- Bussimess Logic Tier: The data and actions which was collected from page was sent to this layer to operate on data. You should not manipulte the data and prepare the response inside Presentation Tier. It is the responsibility of Bussiness Logic Tier.(Spring, CDI)
- Integration Tier: Database access should be done in this layer regardless of the
library technology used (Hibernate, JPA, JDBC).
As you can see in the pic. your JSF managed beans should only be capable of requests from the pages(controller) and page data (model). You can have a look to this answer to understand JSF MVC. Therefore, It is better to not to connect DB inside JSF managed beans. It is not a good practice.
The second part of your question. All technologies, Hibernate, JPA, Spring JDBC, uses JDBC driver of the related DB. JDBC Drivers is the just thing which connects to the DB. However, it is beter to select a method how to connect to DB, Hibernate, JPA or Spring JDBC.
You can download my example application which implements this architecture basically.