1.

What are the core interfaces of Hibernate?

Answer»

The core interfaces of Hibernate framework are used to configure the application, store and retrieve objects and to control transactions. The interfaces are: 

  1. Configuration: The Configuration objects are used to configure the application by setting the configuration file and mapping documents location, retrieving the Hibernate - specific properties etc It also helps create the SessionFactory.  
  2. SessionFactory: The SessionFactory provides obtains Session instances to the application. SessionFactory instances are not lightweight and usually one instance is created for the whole application. If the application accesses multiple databases, it needs one per database. SessionFactory is thread-safe and can holdsecond-level cache of data that is reusable between transactions at a process, or cluster, level. 
  3. Session: The Session is a persistence manager that manages operation like storing and retrieving objects. Instances of Session are inexpensive to create and destroy. Session objects are not thread safe and have to be destroyed once their usefulness is over. Session holds a mandatory first-level cache of PERSISTENT objects that are used when navigating the object graph or looking up objects by identifier. 
  4. QUERY: This interface is used to query the database and control how the query execution takes place. Queries are written using HQL or in the native SQL language of the database being used. A Query instance ALLOWS for the binding of query parameters, limiting the number of results returned by the query, and executing the query. A Query instance cannot be used outside the Session in which it has been created 
  5. Criteria: This interface is used to create and execute queries which are criteria based. Such criteria-based queries are called object-oriented criteria queries.  
  6. Transaction: A transaction REPRESENTS a unit of work. When an application performs some operations on a database, it is called a transaction. We can have multiple operations WITHIN a single transaction and a single commit to commit all the operations at once. If a transaction fails or if an operation in a transaction fails, the transaction can be rolled back. This interface is an optional interface which the application may use or the application may choose to handle its DB operations and transactions through its own code. 


Discussion

No Comment Found