Data persistence in Java Server Faces with Hibernate/JPA
I am planning to build a web application with Java Server Faces but i am unsure how to handle the persistence of my entities. For php projects i am using the Symfony framework with Doctrine 2. I call the persist method of the entity manager mainly in the controllers. So there are no seperate classes for business logic. I tried Hibernate and i think that is a good replace for Doctrine. ;)
The java project is for university and i want to transfer the business logic from the controllers/beans to classes for business logic.
I read articles and tutorials about the data access object and repository pattern (http://docs.spring.io/spring-data/jpa/docs/1.3.0.RELEASE/reference/html/jpa.repositories.html).
In the data access object pattern i have a class for my Entity and an interface and a class for my DAO object/entity, in the repository pattern i have a class for my entity and a class for the repisitory.
But where goes my business logic? Do I have to write an interface and a class per entity for the business logic layer and inside the classes i simply call my dao/repository methods? If so, what is the difference between both patterns?
If I am totally wrong: What is the (industry) standard for data persistence (with Hibernate/JPA) with Java Server Faces?
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.
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.
链接地址: http://www.djcxy.com/p/61424.html上一篇: 在ERB模板中排序YAML输出