Sunday, 14 April 2019

Hibernate Interview Questions For Freshers


Question # 1 What is hibernate in java?

Answer #  Hibernate ORM (Hibernate in short) is an object-relational mapping tool for the Java programming language. It provides a framework for mapping an object-oriented domain model to a relational database. Hibernate also provides data query and retrieval facilities.

Question # 2 Is hibernate better than JDBC?

Answer # JDBC will always give better performance as compared to Hibernate for most of the database vendors. … The choice of hibernate over jdbc and sql queries is not because of the performance but because of reasons mainly object persistence and database independence in terms of not writing database specific queries.

Question # 3 Why do we need hibernate in Java?

Answer # So with JDBC, mapping between Java objects and database tables is done manually. Hibernate reduces lines of code by maintaining object-table mapping itself and returns result to application in form of Java objects. Hibernate, with Transparent Persistence, cache is set to application work space.

Question # 4 What is the use of ORM in Java?

Answer # ORM allows you to use java objects as representation of a relational database. It maps the two concepts (object-oriented and relational) Hibernate is an ORM framework – you describe how your objects are represented in your database, and hibernate handles the conversion.

Question # 5 What is the difference between JPA and Hibernate?

Answer # JPA is the interface, Hibernate is one implementation of that interface. JPA is a specification for accessing, persisting and managing the data between Java objects and the relational database. As the definition says its API, it is only the specification. Hibernate is a JPA provider.

Question # 6 What is the use of Session in hibernate?

Answer # The main runtime interface between a Java application and Hibernate. This is the central API class abstracting the notion of a persistence service. The lifecycle of a Session is bounded by the beginning and end of a logical transaction. (Long transactions might span several database transactions.)

Question # 7 What is the architecture of hibernate?

Answer # Hibernate makes use of the database and configuration data to provide persistence services (and persistent objects) to the application.

Question # 8 What is ORM hibernate?

Answer # Hibernate ORM (Hibernate in short) is an object-relational mapping tool for the Java programming language. It provides a framework for mapping an object-oriented domain model to a relational database.

Question # 9 Can we use only JPA without hibernate?

Answer # You have to specify the persistence provider(Hibernate,EclipseLink) in order to use the JPA implementation. The persistence providers have the implementaion classes for JPA specifications. You can’t just use JPA, cause it is an API =), but there are plenty JPA implementations: EclipseLink.

Question # 10 What are the fetching strategies supported by hibernate?

Answer # Fetch strategies can be declared in the O/R mapping metadata, or over-ridden by a particular HQL or Criteria query. Hibernate defines the following fetching strategies:

Join fetching
Select fetching
Subselect fetching
Batch fetching
Immediate fetching
Lazy collection fetching
“Extra-lazy” collection fetching
Proxy fetching
“No-proxy” fetching
Lazy attribute fetching

No comments:

Post a Comment

Spring Boot @ConfigurationProperties and Properties File

 In this tutorial, you will learn to use @ConfigurationProperties to map properties files to POJO classes in Spring Boot application. Let’s ...