250+ TOP MCQs on Hibernate and Answers

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

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

Answer: c
Clarification: SessionManagement is not a core interface of Hibernate. Configuration, Criteria, SessionFactory, Session, Query and Transaction are the core interfaces of Hibernate.

2. SessionFactory is a thread-safe object.
a) True
b) False

Answer: a
Clarification: SessionFactory is a thread-safe object. Multiple threads can access it simultaneously.

3. Which of the following methods returns proxy object?
a) loadDatabase()
b) getDatabase()
c) load()
d) get()

Answer: c
Clarification: load() method returns proxy object. load() method should be used if it is sure that instance exists.

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

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

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

Answer: b
Clarification: update() method can only be used inside session. update() should be used if session does not contain persistent object.

6. Which of the following is not a state of object in Hibernate?
a) Attached()
b) Detached()
c) Persistent()
d) Transient()

Answer: a
Clarification: Attached() is not a state of object in Hibernate. Detached(), Persistent() and Transient() are the only states in Hibernate.

7. 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

Answer: d
Clarification: Table per class is not an inheritance mapping strategies.

8. 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

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

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

Answer: b
Clarification: Database table configuration is stored in .hbm file.

10. 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

Answer: b
Clarification: addOrder() can be used for ordering the results.

Leave a Reply

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