Hibernate Quiz - MCQ - Multiple Choice Questions


Welcome to our Hibernate quiz! This blog post presents a set of 20+ Multiple Choice Questions (MCQs) to test your knowledge of Hibernate concepts. 

Hibernate is an open-source object-relational mapping (ORM) framework for Java. It provides a way to map Java objects to relational database tables and simplifies the process of interacting with databases in Java applications.

Hibernate acts as a bridge between the object-oriented world of Java and the relational world of databases.

Learn Hibernate at Hibernate ORM Framework Tutorials and Guides

Check out 100+ quiz questions: 100+ Quiz Questions to Test Your Java, Spring Boot, Microservices, Hibernate, REST API Skills 

1. What is Hibernate in Java?

a) A web framework
b) A database
c) An ORM (Object-Relational Mapping) framework
d) A logging framework

2. Which file is used to configure Hibernate settings?

a) hibernate-config.xml
b) hibernate.cfg.xml
c) hibernate-settings.xml
d) hibernate-setup.xml

3. Which Hibernate interface is used to create a session?

a) SessionFactory
b) SessionBuilder
c) SessionFactoryBuilder
d) SessionManager

4. What is the purpose of the Session interface in Hibernate?

a) To manage transactions
b) To manage the database connection
c) To perform CRUD operations on persistent objects
d) To manage the cache

5. Which of the following is a core interface of Hibernate?

a) Configuration
b) Transaction
c) Query
d) All of the above

6. Which method is used to save an object in Hibernate?

a) saveObject()
b) persist()
c) save()
d) store()

7. Which method in Hibernate is used to update an existing record?

a) update()
b) modify()
c) saveOrUpdate()
d) persist()

8. What does the saveOrUpdate() method do in Hibernate?

a) It saves a new object if it does not exist, or updates it if it already exists
b) It only saves a new object
c) It only updates an existing object
d) It deletes an object if it exists

9. What is HQL in Hibernate?

a) Hibernate Query Language
b) Hibernate Quick Language
c) Hibernate Query Library
d) Hibernate Query Listener

10. Which annotation is used to specify an entity in Hibernate?

a) @Table
b) @Entity
c) @Persistence
d) @Data

11. What is the default fetching strategy in Hibernate for @ManyToOne relationships?

a) EAGER
b) LAZY
c) IMMEDIATE
d) NONE

12. Which method is used to delete an object in Hibernate?

a) remove()
b) delete()
c) destroy()
d) erase()

13. What is the use of the Configuration class in Hibernate?

a) To configure Hibernate settings
b) To create a SessionFactory
c) To load Hibernate configurations from an XML file
d) All of the above

14. Which annotation is used to specify a primary key in Hibernate?

a) @Primary
b) @Key
c) @Id
d) @PK

15. Which method is used to execute an HQL query in Hibernate?

a) executeQuery()
b) query()
c) createQuery()
d) execute()

16. Which Hibernate feature allows automatic table creation and schema updates?

a) Schema Generation
b) Auto Schema Update
c) Schema Tool
d) Auto DDL

17. What does the @OneToMany annotation signify in Hibernate?

a) A relationship where one entity is associated with one entity
b) A relationship where one entity is associated with multiple entities
c) A relationship where many entities are associated with one entity
d) A relationship where many entities are associated with many entities

18. What does the @ManyToMany annotation signify in Hibernate?

a) A relationship where one entity is associated with one entity
b) A relationship where one entity is associated with multiple entities
c) A relationship where many entities are associated with one entity
d) A relationship where many entities are associated with many entities

19. Which feature of Hibernate allows caching of data for better performance?

a) DataBuffer
b) QueryCache
c) HibernateCache
d) Second-level cache

20. Which method is used to commit a transaction in Hibernate?

a) commitTransaction()
b) commit()
c) complete()
d) save()

21. What does the @Embedded annotation do in Hibernate?

a) It specifies that a field is embedded in the entity
b) It specifies a relationship between two entities
c) It specifies a primary key
d) It specifies a table name

22. What is the purpose of the @Table annotation in Hibernate?

a) To map a class to a specific database table
b) To specify the columns of a table
c) To specify the primary key
d) To map a class to a specific database column

23. What is the purpose of the @Inheritance annotation in Hibernate?

a) To specify an inheritance strategy for an entity
b) To specify a relationship between entities
c) To specify a primary key strategy
d) To specify a caching strategy

24. What is a native query in Hibernate?

a) A query written in HQL
b) A SQL query written in the native SQL language of the database
c) A query that only retrieves native data types
d) A query that uses a native database connection

25. Which Hibernate feature allows lazy loading of data?

a) EAGER loading
b) IMMEDIATE loading
c) LAZY loading
d) DELAYED loading

Conclusion

We hope you enjoyed our Hibernate quiz! Assessing your knowledge through multiple choice questions helps reinforce your understanding of Hibernate concepts. 

Keep exploring and practicing Hibernate to further enhance your skills in Java persistence and database interaction.

Comments

Spring Boot 3 Paid Course Published for Free
on my Java Guides YouTube Channel

Subscribe to my YouTube Channel (165K+ subscribers):
Java Guides Channel

Top 10 My Udemy Courses with Huge Discount:
Udemy Courses - Ramesh Fadatare