In this blog, I would try to justify why use Hibernate instead of plain JDBC.
What is Hibernate? Hibernate is a powerful, high performance object/relational persistence and query service. What offer Hibernate? What makes better from other solutions?
- First of all, Hibernate is considerated a professional open-source project.
- It implements all Object Oriented Programming features like, associations, inheritance, polymorphism, composition and collections.
- It is transparent to JDBC connections, but doesn't hide.
- It has its query engine, HQL, Criteria and Query by Example, as well as native SQL.
- Hibernate decouples business objects from RDMS, thanks of dialects. You can change your RDMS without changing business database process.
- Hibernate lets you implements quality code, because it takes you to use good practices in patterns world. So easy to develop a Generic DAO pattern.
- Easy to use. It is so easy to implements typical operations of the data layer. For example to insert a tuple into database it is as easy as call session.save(Object obj).
- The model objects (Value Objects or Tranfer Objects), haven't any dependency to hibernate, you musn't extend them from any hibernate class. Hibernate would use reflection and configuration files to know which classes and fields must be supported by database operations.
- Hibernate can work with cache services and transactional services. Typically JTA and JBossCache, but you can use any other.
- Model objects have to be configured into Hibernate Engine. For this configuration, you have three possible strategies, XML Files, JDK5.0 (EJB3) Annotations or Hibernate XDoclet, so developer has variability at his point.
- Hibernate Validator is an annotated solution for validating model objects, you can validate fields of your object model without implementing any conditional, only using field annotations.