Spring ORM

  • ORM tools are used To interact with database.
  • Some examples of ORM tools are
    • Top link
    • Hibernate
    • iBATIS
  • Advantages
    • Less coding is required
    • Easy to test
    • Better exception handling
    • Integrated transaction management.
  • We will use hibernate as an example here.
    • HibernateTemplate class is used to interact hibernate with spring.
    • Spring uses this class to perform operations on database.
  • We need to create entity classes which act as wrapper classes of our database tables.
    • For example, a class called product DAO will act as a wrapper for product table.
    • A class student DAO will act as a wrapper for student table.
  • These entity classes depend on hibernateTemplate class object i.e. we need to inject hibernateTemplate Object in our entity class.
  • Hibernate template then depends on SessionFactory interface which needs to be injected in HibernateTemplate.
  • SessionFactory Is an interface whose implementation class LocalSessionFactoryBean is injected in HibernateTemplate.
  • LocalSessionFactoryBean requires following properties.
    • DataSource which provides Database Properties
      • URL
      • username
      • Password
    • Hibernate properties
      • Dialect
      • Show SQL
      • Format, SQL
    • Annotated classes i.e. our entity classes.

No comments:

Post a Comment

Spring Boot

What is circular/cyclic dependency in spring boot? When two services are interdependent on each other, that is to start one service, we requ...