Spring ORM/Hibernate




Spring Hibernate : Application Architecture



1. Bean/POJO/Entity :
• It is a lightweighted class which binds the data and object.
• It make public data as private (provides Security).
• It contains setter and getter methods.
• If we don't want to create hibernate.hbm.xml, use annotations in that class.

@Entity : It marks class as Entity.
@Table : It specifies tablename. If we don't specify then bydefault it take POJO classname.
@Id : It generates Id.
@Column : It specifies column name.

2. Controller :
• It handles all incoming request and gives appropriate response.
• DispatcherServlet class works as front Controller.

@Controller : marks class as Controller.
@RequestMapping : maps the class with the specified name.
@ModelAttribute : binds the multiple parameters of return value to named model attribute.
@PathVariable : Used in method argument to bind the value of URI template variable.
@autowired : Spring autowire other beans into your class.

3. Service Layer :
To provide logic to operate on the data sent to and from the DAO of the Client.
@Service : Annotate all your service classes.
@Transactional : To handle transaction related to database.

4. Data Access Layer (DAO):
• Used to provide a connection to the Database.
• Used to perform operations on entities.