First, we create classes that represent db entities, ok, done.
Let’s say we use Hibernate session factory and JPA annotations.
Now we must create a DAO: getUserById, getAllUsers() etc.
What do you recommend about transaction management, session factory, how a good design to be made?
JpaTransactionManager. Transactions can be marked in two ways, and they should mark methods of the service classes, not the DAO:@Transactionalon each transactional method (in combination with<tx:annotation-driven />inapplicationContext.xml)<tx:advice>and the appropriate<aop:config>OpenEntityManagerInViewFilterorOpenEntityManagerInViewInterceptorin order to avoidLazyInitializationExceptionRead this for more details.