Hibernate Questions & Answers

Java Questions & Answers – Hibernate

This set of Java Multiple Choice Questions & Answers (MCQs) focuses on “Hibernate”.

1. Which of the following methods hits database always?
a) load()
b) loadDatabase()
c) getDatabase()
d) get()

Explanation: get() method hits database always. Also, get() method does not return proxy object.

2. Which of the following method is used inside session only?
a) merge()
b) update()
c) end()
d) kill()

Explanation: Only the update() method can be used within a session. If the session does not contain a persistent object, update() should be called.

3. Which of the following is not a state of object in Hibernate?
a) Attached()
b) Detached()
c) Persistent()
d) Transient()
Explanation: In Hibernate, Attached() is not an object state. Hibernate has only three states: detached(), persistent(), and transient().

4. Which of the following is not an inheritance mapping strategies?
a) Table per hierarchy
b) Table per concrete class
c) Table per subclass
d) Table per class

Explanation: Table per class is not an inheritance mapping strategies.

5. Which of the following is not an advantage of using Hibernate Query Language?
a) Database independent
b) Easy to write query
c) No need to learn SQL
d) Difficult to implement

Explanation: HQL is easy to implement. Also, to implement it HQL it is not dependent on a database platform.

6. In which file database table configuration is stored?
a) .dbm
b) .hbm
c) .ora
d) .sql

Explanation: Database table configuration is stored in .hbm file.

7. Which of the following is not an advantage of Hibernate Criteria API?
a) Allows to use aggregate functions
b) Cannot order the result set
c) Allows to fetch only selected columns of result
d) Can add conditions while fetching results

Explanation: addOrder() can be used for ordering the results.

8. Which of the following is not a core interface of Hibernate?
a) Configuration
b) Criteria
c) SessionManagement
d) Session

Explanation: SessionManagement is not a Hibernate core interface. Hibernate’s core interfaces are Configuration, Criteria, SessionFactory, Session, Query, and Transaction.
9. SessionFactory is a thread-safe object.
a) True
b) False

Explanation: SessionFactory is a thread-safe object. Multiple threads can access it simultaneously.
10. Which of the following methods returns proxy object?
a) loadDatabase()
b) getDatabase()
c) load()
d) get()

Explanation: The proxy object is returned by the load() method. If it is certain that the object exists, the load() function should be used.

Hibernate ORM (or just Hibernate) is a Java programming language object–relational mapping tool. It provides a framework for translating a relational database to an object-oriented domain model. Hibernate solves object–relational impedance mismatch issues by using high-level object handling routines instead of direct, permanent database calls. The mapping of Java classes to database tables, as well as mapping of Java data types to SQL data types, is Hibernate’s main functionality. Hibernate also allows you to query and retrieve data.

Leave a Reply

Your email address will not be published. Required fields are marked *