This set of Java Multiple Choice Questions & Answers (MCQs) on “Hibernate”.
1. Which of the following is not a core interface of Hibernate? Answer: c 2. SessionFactory is a thread-safe object. Answer: a 3. Which of the following methods returns proxy object? Answer: c 4. Which of the following methods hits database always? Answer: d 5. Which of the following method is used inside session only? Answer: b 6. Which of the following is not a state of object in Hibernate? Answer: a 7. Which of the following is not an inheritance mapping strategies? Answer: d 8. Which of the following is not an advantage of using Hibernate Query Language? Answer: d 9. In which file database table configuration is stored? Answer: b 10. Which of the following is not an advantage of Hibernate Criteria API? Answer: b
a) Configuration
b) Criteria
c) SessionManagement
d) Session
Clarification: SessionManagement is not a core interface of Hibernate. Configuration, Criteria, SessionFactory, Session, Query and Transaction are the core interfaces of Hibernate.
a) True
b) False
Clarification: SessionFactory is a thread-safe object. Multiple threads can access it simultaneously.
a) loadDatabase()
b) getDatabase()
c) load()
d) get()
Clarification: load() method returns proxy object. load() method should be used if it is sure that instance exists.
a) load()
b) loadDatabase()
c) getDatabase()
d) get()
Clarification: get() method hits database always. Also, get() method does not return proxy object.
a) merge()
b) update()
c) end()
d) kill()
Clarification: update() method can only be used inside session. update() should be used if session does not contain persistent object.
a) Attached()
b) Detached()
c) Persistent()
d) Transient()
Clarification: Attached() is not a state of object in Hibernate. Detached(), Persistent() and Transient() are the only states in Hibernate.
a) Table per hierarchy
b) Table per concrete class
c) Table per subclass
d) Table per class
Clarification: Table per class is not an inheritance mapping strategies.
a) Database independent
b) Easy to write query
c) No need to learn SQL
d) Difficult to implement
Clarification: HQL is easy to implement. Also, to implement it HQL it is not dependent on a database platform.
a) .dbm
b) .hbm
c) .ora
d) .sql
Clarification: Database table configuration is stored in .hbm file.
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
Clarification: addOrder() can be used for ordering the results.