DAO Level and Services in Spring: Session Management

Do I understand the principles of connecting DAO and the level of service? DAO performs the removal of basic objects, for example, id from db.

The service layer USES a DAO object and can call MORE THAN ONE DAO METHOD in a single function. So, the level of service should:

  • create an instance of the DAO implementation object

  • call as many DAO methods as possible

If a Dao implements an interface, should the DAO interface have a method setSessionFactory()?

As declaratively noted in Spring:

  • DAO Object

  • Service level methods and class in general

so that he gives what is needed?

+3
source share
3 answers

, setSessionFactory(), DAO. DAO Spring, SessionFactory DAO.

Hibernate SessionFactory.getCurrentSession(), , SessionFactory DAO , Session .

, :

@Transactional
public void doSomething(){
    dao1.makeCall();
    dao2.makeOtherCall();
}

SessionFactory, DAO , Session. .

+4

, , , setSessionFactory(), DAO. Hibernate DAO-, DAO Hibernate.

- (, ORM - ) ( DAO) .

setSessionFactory DAO-, , DAO, , Hibernate. , , .

+7
  • spring ( ).
  • DAO sessionFactory.getCurrentSession() tp
  • there is SessionFactoryintroduced in the DAO.
  • have a DAO in the field singleton
  • use declarative transactions (either with <aopor with @Transactional)
  • DAO is injected into service objects through regular dependency injection. Similarly, service classes are introduced where they are needed.
+2
source

Source: https://habr.com/ru/post/1739595/


All Articles