The hibernate framework simplifies the development of Java applications and database interactions. Hibernate is an open source, lightweight ORM (Object Relational Mapping) tool.
ORM Tools simplify the creation of browsing data, data processing, and data access. It is a programming technique for mapping objects to data (tables) stored in a database.
The ORM tool internally interacts with the database using the JDBC API.
Benefits of Hibernate framework:
- Open source and lightweight: Hibernate see is based on LGPL license and lightweight open source tools.
- Fast performance: The Hibernate framework performs quickly because the cache is used inside the hibernate framework. There are two types of caches in the Hibernate framework: first-level cache and level two cache. The first-level cache is enabled by default.
- Database Independent query: HQL (Hibernate query Language) is an object-oriented SQL version. It generates a database-independent query. Therefore, you do not need to write database-specific query statements. Before hibernate, if the project modifies the database, the SQL query needs to be changed, resulting in complex maintenance.
- Automatically create tables: The Hibernate framework provides the ability to automatically create database tables. Therefore, you do not have to manually create tables in the database.
- Simplifies complex connections: You can easily get data from multiple tables in the Hibernate framework.
- Provides query statistics and database status: Hibernate supports query caching and provides statistical information about queries and database status.
Hibernate schemas include many object persistence objects, session factories, thing factories, connection factories, session transactions, and so on. Hibernate architecture can be divided into 4 layers Java application layer, Hibernate framework layer, backhand API layer and database layer
Application------presistent Object-----HIBERNATE Mapping file, Configuration file--database
The Presistent object section includes: Sessionfactory, Session, Transaction Factory, Transaction, Connection Provider.
The hibernate framework can use many object session factories, sessions, transactions, and existing Java APIs such as JDBC (Java database connection), JTA (Java transaction API), and Jndi (Java named Directory interface).
To create a hibernate application, you need to know the elements of the hibernate schema.
Session Factory (Sessionfactory)
Sessionfactory is the ConnectionProvider session and client factory. It has a level two cache of data (optional). The Org.hibernate.SessionFactory interface provides a factory method to get the object of the session.
Sessions (session)
The Session object provides an interface between the application and the data stored in the database. It is a short life cycle object and wraps the JDBC connection. It is a business, a query, and a standard factory. It also provides transactions, queries, and standard factory methods.
Transactions (Transaction)
The transaction object specifies the atomic unit of work, which is an optional option. The Org.hibernate.Transaction interface provides a method for transaction management.
Connection provider (ConnectionProvider)
It is a JDBC connection factory. It abstracts out the application from DriverManager or datasource. is an optional item.
Transaction Factory (Transactionfactory), is an optional option.
In addition, you can create hibernate applications using annotations. There are many annotations that can be used to create hibernate applications such as @entity, @Id, @Table, etc. Hibernate annotations are based on the JPA2 specification. and supports all features. All of the JPA annotations are defined in the javax.persistence.* package. Hibernate Entitymanager implements the interfaces and lifecycles defined by the JPA specification. The advantage of using hibernate annotations is that you do not need to create a mapping (*.hbm.xml) file to directly create an object association.
@Entity note mark the class as an entity and place it on the class name.
@Table note Specifies the table name of the database for which you want to associate this entity class. Put on the class name, format @table (name= "table name")
If you do not use the @table comment, Hibernate uses the name of the class as the table. The default condition.
@Id comment marks the identifier of the entity.
@Column Note Specifies the details of the column for this property or field. If the bit specifies a @column comment, the property name is used as the column name, by default.
Hibernate Framework Understanding