I am trying to create a Java EE Web Application with JSF 2, Spring and Hibernate. I'm fairly new to this stack, so I need some help on best practices in organizing an application.
My initial objective is simple, a User logins in, and her session is not closed until she logs out. Here is what I have come up with so far:
User entity class, annotated with @Entity so that it is persisted. Not registered as a JSF or managed bean. Simple POJO with private fields (name, surname etc) and with accessors.
An interface for a DAO to interact with the User class: getUserById(), saveUser() etc.
An implementation of the DAO. Marked with Spring's @Repository and with Hibernate's SessionFactory @Autowired and added in ApplicationContext via component-scan.
Now, for a user browsing the site, I believe I should not create a session-scoped bean from my User class, is that correct? I think the best practice would be to never directly touch the User class, only through DAO.
So, do I need to have another bean UserManaged (probably ManagedBean and session scoped) that duplicates the fields of the User class; and use that in my JSF files? So, the beans user that are created when user interacts with the website should be handled by JSF, and the rest by Spring? But wouldn't that duplication break the DRY principle, having the same fields as in User in another UserManaged class?