List of Features in Hibernate
- Relationship: Hibernate supports relationships like One-To-One, One-To-One, One-To-Many, Many-To-Many.
- Support Association: Hibernate supports association type of relationship: composition and aggregation.
- Support Inheritance: : In hibernate, if we save derived class object, then its base class object will also be stored into the database, it means hibernate supports inheritance mechanism.
- Support Primary Key: Hibernate has capability to generate primary keys automatically while we are storing the records into database
- Support Composite Key: Hibernate has capability to generate composite primary keys based on the provided meta data.
- Support Validation: Hibernate support domain model validation which enable by annotation. Hibernate has one of the project which is called Hibernate Validator which has rich set of validation.
- Support Full-Text Search: Hibernate has a project which is called Hibernate Search which support full-text search on domain model object.
- Supports Collection (List/Set/Map): Hibernate supports Java collections data structure: List, Set, Map.
- Caching: Hibernate supports 2 level of caching, first level and second level. Caching mechanism reduces the number of round trips between an application and the database improve our user experience and performance of application.
- HQL (Hibernate Query Language): Hibernate has its own query language, i.e HQL (Hibernate query language) which is database independent
- No locking of DB: Hibernate says don’t rely on database by writing your own SQL query. Prefer not to write SQL query in project if you are using Hibernate.
- No need of try-catch-exception block: when we write code in JDBC, we use to catch
SQLExceptionand transform into another exception it means, all exceptions are checked exceptions, so we must write code in try-catch-exception and throws. But in hibernate we only have Un-checked/run-time exceptions, so no need to write try-catch-exception block and throws clause. Hibernate we have the translator which converts checked/compile time to Un-checked/run-time
- Auto-Generation: While we are inserting any record, if we don’t have any particular table in the database, JDBC will rises an error like “View not exist”, and throws exception, but in case of Hibernate, if it not found any table in the database this will create the table for us , if we configured in our meta-data configuration file.
- Auto-Generation Query on Console: if we have enable auto generation of query that will print/display on console or log file which help most of the times when you debug any issue.
- Support Annotation: Hibernate supports annotations, apart from XML
- Support many databases: Hibernate provided Dialect classes, so we no need to write SQL queries in Hibernate, instead we use the methods provided by that API.
- Pagination Support: Getting pagination in hibernate is quite simple.
- Hierarchal Data: fetching of Hierarchal data in Hibernate is very simple, e.g. in catalog system, you can pull catalog -> category -> product -> product variation in one go, which is very complex pull hierarchal data in normal JDBC.
- Smart Query Generation: If you think from developer mind set, most of the time you are not able to tune our query. why we not able to tune our query? there could be various reason for this: you may know how to tune but don’t have sufficient time , sometimes you know how to tune but due to laziness, sometime don’t know how to tune, sometimes focus is to finish our functionality, sometimes we know but think later point of time will do this but later never come 🙂 you know. Hibernate generate smart query by us using its smart query generation engine.
- support Query Criteria: This is powerful component in Hibernate, which enable rich set of filter and project. if you want to generate your own query on run time that is most difficult to do in simple JDBC and time consuming test case. But when you are using Query Criteria of Hibernate it’s very easy based on condition specially for search functionality on 3/4 fields.
Your comments are welcome to add on top of this.