{"id":6329,"date":"2020-11-17T13:44:34","date_gmt":"2020-11-17T13:44:34","guid":{"rendered":"https:\/\/www.temok.com\/blog\/?p=6329"},"modified":"2023-12-08T07:12:12","modified_gmt":"2023-12-08T07:12:12","slug":"hibernate-interview-questions-and-answers","status":"publish","type":"post","link":"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/","title":{"rendered":"50+ Hibernate Interview Questions and Answers To Boost Your Java Skills"},"content":{"rendered":"<span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><\/span> <span class=\"rt-time\"> 11<\/span> <span class=\"rt-label rt-postfix\">min read<\/span><\/span>\r\n<p>Hibernate is a popular ORM tool that is used in enterprise applications for database-related operations and other Java applications. Therefore, top companies are looking for hibernate experts for their day-to-day operations. So, I have decided to write an article on the hibernate interview questions and answers which is mandatory to polish your knowledge before the interview.<\/p>\r\n\r\n\r\n\r\n<p>Hibernate has significant importance in the Java world because it frees Java developers from writing complex JDBC code converting SQL columns into object properties. It also offers out-of-box solutions on proxying, caching, and lazy loading which improves the overall performance of Java web applications. So, the spring and hibernate interview questions are mostly asked in Java interviews for web development positions.\u00a0\u00a0<\/p>\r\n\r\n\r\n\r\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a4e71d43a026\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a4e71d43a026\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#Hibernate_Interview_Questions\" >Hibernate Interview Questions<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#General_and_Architecture_Questions\" >General and Architecture Questions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#Configuration_and_Statistics\" >Configuration and Statistics<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#Object_Mapping\" >Object Mapping<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#Core_Interfaces\" >Core Interfaces<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#Data_Manipulation\" >Data Manipulation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#Transaction_Management\" >Transaction Management<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#Cache_Management\" >Cache Management<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#Hibernate_Interview_Questions-2\" >Hibernate Interview Questions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#1_What_is_Hibernate\" >1. What is Hibernate?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#2_What_is_ORM\" >2. What is ORM?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#3_What_is_the_Java_Persistence_API_JPA\" >3. What is the Java Persistence API (JPA)?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#4_What_is_the_major_difference_between_Hibernate_JPA\" >4. What is the major difference between Hibernate &amp; JPA?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#5_Explain_Hibernate_Architecture\" >5. Explain Hibernate Architecture<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#6_What_is_HQL_in_Hibernate\" >6. What is HQL in Hibernate?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#7_How_is_the_HQL_query_created\" >7. How is the HQL query created?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#8_Whats_the_general_hibernate_flow_using_RDBMS\" >8. What\u2019s the general hibernate flow using RDBMS?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#9_What_is_the_Hibernate_validator_framework\" >9. What is the Hibernate validator framework?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#10_What_are_the_main_benefits_of_using_the_Hibernate_Framework\" >10. What are the main benefits of using the Hibernate Framework?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#11_What_are_the_key_advantages_of_Hibernate_over_JDBC\" >11. What are the key advantages of Hibernate over JDBC?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#12_What_design_patterns_are_implemented_in_Hibernate\" >12. What design patterns are implemented in Hibernate?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#13_List_some_of_the_popular_databases_supported_by_Hibernate\" >13. List some of the popular databases supported by Hibernate<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#14_What_are_the_best_practices_could_you_recommend_when_youre_using_Hibernate\" >14. What are the best practices could you recommend when you\u2019re using Hibernate?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#Configuration_and_Statistics-2\" >Configuration and Statistics<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#15_What_are_ways_to_configure_Hibernate\" >15. What are ways to configure Hibernate?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#16_What_is_the_purpose_of_dialect_in_the_configuration\" >16. What is the purpose of dialect in the configuration?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#17_How_to_integrate_Hibernate_with_a_Spring_Framework\" >17. How to integrate Hibernate with a Spring Framework?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-28\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#18_What_is_a_Hibernate_mapping_file\" >18. What is a Hibernate mapping file?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-29\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#19_How_is_SQL_query_created_in_Hibernate\" >19. How is SQL query created in Hibernate?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-30\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#20_How_to_get_Hibernate_statistics\" >20. How to get Hibernate statistics?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-31\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#21_Enlist_two_components_of_the_Hibernate_configuration_object\" >21. Enlist two components of the Hibernate configuration object.<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-32\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#Object_Mapping-2\" >Object Mapping<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-33\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#22_How_to_map_an_entity_to_multiple_tables\" >22. How to map an entity to multiple tables?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-34\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#23_What_are_the_requirements_for_Entity_class\" >23. What are the requirements for Entity class?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-35\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#24_What_are_the_collection_types_in_hibernation\" >24. What are the collection types in hibernation?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-36\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#25_What_is_a_Bag_collection\" >25. What is a Bag collection?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-37\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#26_What_is_the_difference_between_a_sorted_collection_and_an_ordered_collection\" >26. What is the difference between a sorted collection and an ordered collection?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-38\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#Core_Interfaces-2\" >Core Interfaces<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-39\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#27_What_are_the_core_interfaces_of_Hibernate\" >27. What are the core interfaces of Hibernate?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-40\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#28_What_is_a_Hibernate_Session\" >28. What is a Hibernate Session?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-41\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#29_Is_the_session_thread-safe\" >29. Is the session thread-safe?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-42\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#30_What_is_a_difference_between_openSession_and_getCurrentSession\" >30. What is a difference between openSession() and getCurrentSession()?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-43\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#31_What_is_SessionFactory\" >31. What is SessionFactory?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-44\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#32_Is_SessionFactory_thread-safe\" >32. Is SessionFactory thread-safe?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-45\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#Data_Manipulation-2\" >Data Manipulation<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-46\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#33_What_is_eager_loading_in_Hibernate\" >33. What is eager loading in Hibernate?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-47\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#34_What_is_lazy_loading_in_Hibernate\" >34. What is lazy loading in Hibernate?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-48\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#35_What_is_a_lazy_initialization\" >35. What is a lazy initialization?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-49\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#36_What_is_cascading_in_hibernate\" >36. What is cascading in hibernate?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-50\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#37_What_is_the_key_difference_between_merge_and_update_methods\" >37. What is the key difference between merge() and update() methods?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-51\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#38_What_is_the_main_difference_between_save_and_persist_methods\" >38. What is the main difference between save() and persist() methods?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-52\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#39_What_is_the_N1_problem\" >39. What is the N+1 problem?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-53\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#40_What_is_a_Named_Query\" >40. What is a Named Query?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-54\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#41_What_is_the_key_benefit_of_Hibernate_Criteria_API\" >41. What is the key benefit of Hibernate Criteria API?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-55\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#Transaction_Management-2\" >Transaction Management<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-56\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#42_What_is_a_transaction\" >42. What is a transaction?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-57\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#43_What_is_transaction_propagation\" >43. What is transaction propagation?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-58\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#44_Enlist_the_hibernate_isolation_levels\" >44. Enlist the hibernate isolation levels.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-59\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#45_What_is_the_difference_between_an_optimistic_lock_and_a_pessimistic_lock\" >45. What is the difference between an optimistic lock and a pessimistic lock?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-60\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#Cache_Management-2\" >Cache Management<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-61\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#46_How_many_cache_levels_do_you_know_in_Hibernate\" >46. How many cache levels do you know in Hibernate?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-62\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#47_What_is_the_1st_level_cache\" >47. What is the 1st level cache?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-63\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#48_Is_it_possible_to_disable_1st_level_cache\" >48. Is it possible to disable 1st level cache?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-64\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#49_What_is_the_2nd_level_cache\" >49. What is the 2nd level cache?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-65\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#50_What_is_the_difference_between_1st_and_2nd_levels_of_cache\" >50. What is the difference between 1st and 2nd levels of cache?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-66\" href=\"https:\/\/www.temok.com\/blog\/hibernate-interview-questions-and-answers\/#51_How_to_clear_cache\" >51. How to clear cache?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Hibernate_Interview_Questions\"><\/span><strong>Hibernate Interview Questions<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"General_and_Architecture_Questions\"><\/span><strong><a class=\"aioseop-link\" href=\"#1\">General and Architecture Questions<\/a><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>What is Hibernate?<\/li>\r\n<li>What is ORM?<\/li>\r\n<li>What is the Java Persistence API (JPA)?<\/li>\r\n<li>What is the difference between Hibernate and JPA?<\/li>\r\n<li>Explain Hibernate architecture<\/li>\r\n<li>What is HQL in Hibernate?<\/li>\r\n<li>How is the HQL query created?<\/li>\r\n<li>What\u2019s the general hibernate flow using RDBMS?<\/li>\r\n<li>What is the Hibernate validator framework?<\/li>\r\n<li>What are the main benefits of using the Hibernate Framework?<\/li>\r\n<li>What are the key advantages of Hibernate over JDBC?<\/li>\r\n<li>What design patterns are implemented in Hibernate?<\/li>\r\n<li>List some of the popular databases supported by Hibernate<\/li>\r\n<li>What are the best practices could you recommend when you\u2019re using Hibernate?<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Configuration_and_Statistics\"><\/span><strong><a class=\"aioseop-link\" href=\"#2\">Configuration and Statistics<\/a><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>What are ways to configure Hibernate?<\/li>\r\n<li>What is the purpose of dialect in the configuration?<\/li>\r\n<li>How to integrate Hibernate with a Spring Framework?<\/li>\r\n<li>What is the Hibernate mapping file?<\/li>\r\n<li>How is SQL query created in Hibernate?<\/li>\r\n<li>How to get Hibernate statistics?<\/li>\r\n<li>Enlist two components of the Hibernate configuration object.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Object_Mapping\"><\/span><strong><a class=\"aioseop-link\" href=\"#3\">Object Mapping<\/a><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>How to map an entity to multiple tables?<\/li>\r\n<li>What are the requirements for Entity class?<\/li>\r\n<li>What are the collection types in hibernation?<\/li>\r\n<li>What is a Bag collection?<\/li>\r\n<li>What is the difference between a sorted collection and an ordered collection?<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Core_Interfaces\"><\/span><strong><a class=\"aioseop-link\" href=\"#4\">Core Interfaces<\/a><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>What are the core interfaces of Hibernate?<\/li>\r\n<li>What is a Hibernate Session?<\/li>\r\n<li>Is the session thread-safe?<\/li>\r\n<li>What is the difference between openSession() and getCurrentSession()?<\/li>\r\n<li>What is SessionFactory?<\/li>\r\n<li>Is SessionFactory thread-safe?<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Data_Manipulation\"><\/span><strong><a class=\"aioseop-link\" href=\"#5\">Data Manipulation<\/a><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>What is eager loading in Hibernate?<\/li>\r\n<li>What is lazy loading in Hibernate?<\/li>\r\n<li>What is a lazy initialization?<\/li>\r\n<li>What is cascading in hibernate?<\/li>\r\n<li>What is the key difference between merge() and update() methods?<\/li>\r\n<li>What is the main difference between methods save() and persist()?<\/li>\r\n<li>What is the N+1 problem?<\/li>\r\n<li>What is a Named Query?<\/li>\r\n<li>What are the benefits of Hibernate Criteria API?<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Transaction_Management\"><\/span><strong><a class=\"aioseop-link\" href=\"#6\">Transaction Management<\/a><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>What is a transaction?<\/li>\r\n<li>What is transaction propagation?<\/li>\r\n<li>Enlist the hibernate isolation levels.<\/li>\r\n<li>What is the difference between an optimistic lock and a pessimistic lock?<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Cache_Management\"><\/span><strong><a class=\"aioseop-link\" href=\"#7\">Cache Management<\/a><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>How many cache levels do you know in Hibernate?<\/li>\r\n<li>What is the 1st level cache?<\/li>\r\n<li>Is it possible to disable 1st level cache?<\/li>\r\n<li>What is the 2nd level cache?<\/li>\r\n<li>What is the difference between 1st and 2nd levels of cache?<\/li>\r\n<li>How to clear the cache?<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id=\"1\"><span class=\"ez-toc-section\" id=\"Hibernate_Interview_Questions-2\"><\/span><strong>Hibernate Interview Questions<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_What_is_Hibernate\"><\/span><strong>1. What is Hibernate? <\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Hibernate_(framework)\" target=\"_blank\" rel=\"noopener\">Hibernate<\/a> is written in Java and it is based on JVM (Java Virtual Machine). It is an open-source software that is used for mapping Java classes to data tables and Java data types to SQL data types. Hibernate makes it easier to create objects independent of database software and provides a reference implementation of Java persistence API that is used for CRUD operations.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_What_is_ORM\"><\/span><strong>2. What is ORM?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Object Relational Mapping (ORM) is a programming technique that is used to convert data between relational databases and OOP (Object Oriented Programming) languages such as C#, Java, etc.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_What_is_the_Java_Persistence_API_JPA\"><\/span><strong>3. What is the Java Persistence API (JPA)?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Java Persistence API (also known as JPA) has the specification for managing the relational data in several applications. JPA&#8217;s current version 2.1 was started in July 2011 but approved as final on 22 May 2013. It also helps us in writing implementation-independent code.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_What_is_the_major_difference_between_Hibernate_JPA\"><\/span><strong>4. What is the major difference between Hibernate &amp; JPA?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Hibernate is an ORM tool that is used to save the state of any Java object into the database whereas JPA defines the management of relational data in the Java applications.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Explain_Hibernate_Architecture\"><\/span><strong>5. Explain Hibernate Architecture<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Hibernate architecture is based on many objects including session factory, persistent object, connection factory, transaction, session, transaction factory, etc. It is categorized into the following layers:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Java application layer<\/li>\r\n<li>Hibernate framework layer<\/li>\r\n<li>Backhand API layer<\/li>\r\n<li>Database layer<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p>As you can view in the diagram given below:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6336\" src=\"https:\/\/i0.wp.com\/www.blog.temok.com\/wp-content\/uploads\/2020\/11\/blg2.jpg?resize=750%2C500&#038;ssl=1\" alt=\"Explain Hibernate Architecture\" width=\"750\" height=\"500\" srcset=\"https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2020\/11\/blg2.jpg?w=750&amp;ssl=1 750w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2020\/11\/blg2.jpg?resize=300%2C200&amp;ssl=1 300w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6_What_is_HQL_in_Hibernate\"><\/span><strong>6. What is HQL in Hibernate?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Hibernate Query Language (HQL) is an object-oriented language that is independent of the database and considers the Java objects in a similar way as that of SQL.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"7_How_is_the_HQL_query_created\"><\/span><strong>7. How is the HQL query created?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>The HQL query is created with the following syntax:<\/p>\r\n\r\n\r\n\r\n<p>Session.createQuery<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"8_Whats_the_general_hibernate_flow_using_RDBMS\"><\/span><strong>8. What\u2019s the general hibernate flow using RDBMS?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>The flow of hibernate communication with RDBMS is:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>The hibernate flow using RDBMS starts with loading the Hibernate configuration file and creation of the configuration object (It will automatically load all hbm mapping files)<\/li>\r\n<li>The session factory will be created from the configuration object<\/li>\r\n<li>Get one session from this session factory<\/li>\r\n<li>Create HQL Query<\/li>\r\n<li>Now run the query to get the list having Java objects<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"9_What_is_the_Hibernate_validator_framework\"><\/span><strong>9. What is the Hibernate validator framework?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>The hibernate validator framework allows to expression and validation of different constraints of the application by overriding and extending through XML. Moreover, it is available for both server and client-side programming.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"10_What_are_the_main_benefits_of_using_the_Hibernate_Framework\"><\/span><strong>10. What are the main benefits of using the Hibernate Framework?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>The following are the main benefits of using the Hibernate Framework:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>We can focus on our business logic because it eliminates all the boilerplate code that comes with JDBC and takes care of managing resources.<\/li>\r\n<li>It has powerful query language (HQL) which is based on object-oriented concepts and supports inheritance, polymorphism, and association.<\/li>\r\n<li>Hibernate has great support for XML and JPA annotations that make our code implementation independent.<\/li>\r\n<li>It is an open-source project and tons of online documentation are available over the internet.<\/li>\r\n<li>Hibernate supports lazy initialization and performs the database queries only when it is required.<\/li>\r\n<li>For database vendor-specific features, hibernate is best because we can execute native SQL queries.<\/li>\r\n<li>Hibernate cache helps to get better performance<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"11_What_are_the_key_advantages_of_Hibernate_over_JDBC\"><\/span><strong>11. What are the key advantages of Hibernate over JDBC?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>The following are the key advantages of the hibernate framework over JDBC:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Hibernate makes the code cleaner and more readable by removing boilerplate code.<\/li>\r\n<li>Unlike JDBC API, Hibernate supports inheritance, associations, and collections.<\/li>\r\n<li>Hibernate provides transaction management while in JDBC API we need to write code for transaction management using commit and rollback.<\/li>\r\n<li>HQL is more object-oriented and very close to Java programming language. For JDBC, it is mandatory to write native SQL queries.<\/li>\r\n<li>JDBC has poor performance because it doesn\u2019t support caching but Hibernate has great caching options to provide the best performance.<\/li>\r\n<li>Hibernate supports JPA annotations whereas JDBC code is tightly coupled with the application.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"12_What_design_patterns_are_implemented_in_Hibernate\"><\/span><strong>12. What design patterns are implemented in Hibernate?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>The following design patterns are used in the Hibernate framework:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Domain Model Pattern is an object model of the domain that incorporates both behavior and data<\/li>\r\n<li>Data Access Object (DAO) Design Pattern<\/li>\r\n<li>Abstract Factory<\/li>\r\n<li>Data Mapper<\/li>\r\n<li>Query Object for Criterion API<\/li>\r\n<li>Fa\u00e7ade<\/li>\r\n<li>Proxy for lazy loading<\/li>\r\n<li>Object-Relational Mapping (ORM)<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"13_List_some_of_the_popular_databases_supported_by_Hibernate\"><\/span><strong>13. List some of the popular databases supported by Hibernate<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Following are the hibernate-supported databases:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>DB2<\/li>\r\n<li>MySQL<\/li>\r\n<li>Oracle<\/li>\r\n<li>HSQL<\/li>\r\n<li>FrontBase<\/li>\r\n<li>PostgreSQL<\/li>\r\n<li>Sybase SQL Server<\/li>\r\n<li>Informix Dynamic Server<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"14_What_are_the_best_practices_could_you_recommend_when_youre_using_Hibernate\"><\/span><strong>14. What are the best practices could you recommend when you\u2019re using Hibernate?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Following best practices are recommended when we use the hibernate:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Persistent classes should Implement hashCode() and equals()<\/li>\r\n<li>Avoid references to the ID in the persistent class&#8217; method equals()<\/li>\r\n<li>Avoid public\/protected setter for the generated identifier field<\/li>\r\n<li>Avoid many-to-many association<\/li>\r\n<li>Never use an array to map a collection<\/li>\r\n<li>equals() and hashCode() must access the fields through getter methods<\/li>\r\n<li>Avoid non-serializable Entities<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id=\"2\"><span class=\"ez-toc-section\" id=\"Configuration_and_Statistics-2\"><\/span><strong>Configuration and Statistics<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"15_What_are_ways_to_configure_Hibernate\"><\/span><strong>15. What are ways to configure Hibernate?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Hibernate can be configured in the following ways:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li><strong>Using APIs (programmatically):<\/strong> In a programmatical way, the APIs are used to load the hbm file along with the database driver providing connection details.<\/li>\r\n<li><strong>Using XML File:<\/strong> By specifying the database connection details in an XML configuration file named hibernate.cfg.xml that\u2019s loaded along with the hbm file.<\/li>\r\n<li><strong>Using Properties File:<\/strong> By using a .properties file named hibernate.properties.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"16_What_is_the_purpose_of_dialect_in_the_configuration\"><\/span><strong>16. What is the purpose of dialect in the configuration?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>In the configuration, the dialect knows which database you are using so that it can be switched to the database-specific SQL generator code whenever you need it.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"17_How_to_integrate_Hibernate_with_a_Spring_Framework\"><\/span><strong>17. How to integrate Hibernate with a Spring Framework?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Hibernate is one of the popular ORM frameworks and Spring is a widely used Java EE framework. So, the spring hibernate combination is used in a lot of enterprise-level applications. Following are the simple steps for hibernate and spring integration:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Create a table in the database (optional step)<\/li>\r\n<li>Create an applicationContext.xml file that contains DataSource and SessionFactory etc.<\/li>\r\n<li>Create Employee.java file (persistent class)<\/li>\r\n<li>Create employee.hbm.xml file (mapping file)<\/li>\r\n<li>Create EmployeeDao.java file that uses HibernateTemplate<\/li>\r\n<li>Create InsertTest.java file that calls methods of the EmployeeDao class<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"18_What_is_a_Hibernate_mapping_file\"><\/span><strong>18. What is a Hibernate mapping file?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>The mapping file is one of the key features of hibernation because it is a compulsory feature for every ORM tool. It is a mechanism of placing an object property into columns of a table because it establishes a relationship between two database tables as an attribute in their model and allows you to easily navigate the criteria queries and associations in your model.\u00a0<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"19_How_is_SQL_query_created_in_Hibernate\"><\/span><strong>19. How is SQL query created in Hibernate?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>The SQL query is created using the following syntax:<\/p>\r\n\r\n\r\n\r\n<p>Session.createSQLQuery<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"20_How_to_get_Hibernate_statistics\"><\/span><strong>20. How to get Hibernate statistics?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>We can get the hibernate statistics by setting the property hibernate.generate_statistics to true. It will show several useful metrics but it is only available in development mode.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"21_Enlist_two_components_of_the_Hibernate_configuration_object\"><\/span><strong>21. Enlist two components of the Hibernate configuration object.<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Database Connection<\/p>\r\n\r\n\r\n\r\n<p>Class Mapping Setup<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id=\"3\"><span class=\"ez-toc-section\" id=\"Object_Mapping-2\"><\/span><strong>Object Mapping<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"22_How_to_map_an_entity_to_multiple_tables\"><\/span>22. <strong>How to map an entity to multiple tables?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Following are the simple steps to map an entity to 2 database tables:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Annotate your entity with JPA\u2019s @Table and @SecondaryTable annotations, in addition, provide the names of the first and second tables as the name parameters.<\/li>\r\n<li>Annotate each attribute that you need to map to the secondary table with a @Column annotation and add the secondary table name as the value of the table attribute.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"23_What_are_the_requirements_for_Entity_class\"><\/span><strong>23. What are the requirements for Entity class?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>The following are the requirements for an entity class:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>It essentially annotated with the javax.persistence.Entity annotation<\/li>\r\n<li>The class may have other constructor methods but it must have a public or protected, no-argument constructor<\/li>\r\n<li>The persistent instance variables or no methods must be declared final but the class will never be declared final<\/li>\r\n<li>When the entity instance is passed using its value as a detached object then the class must implement the Serializable interface<\/li>\r\n<li>Entities may extend both entity &amp; non-entity classes, but non-entities only used to extend entity classes<\/li>\r\n<li>Persistent instance variables must be declared using private, protected, or package-private and can be accessed directly by the entity class\u2019s methods through accessor or business methods<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"24_What_are_the_collection_types_in_hibernation\"><\/span><strong>24. What are the collection types in hibernation?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Bag<\/li>\r\n<li>Set<\/li>\r\n<li>List<\/li>\r\n<li>Array<\/li>\r\n<li>Map<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"25_What_is_a_Bag_collection\"><\/span><strong>25. What is a Bag collection?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>The bag is a Java collection that is used to store the elements without caring about sequencing and allow duplicate elements in the list. In simple words, it is a random grouping of the objects in a list that is mapped with a &lt;bag&gt; element.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"26_What_is_the_difference_between_a_sorted_collection_and_an_ordered_collection\"><\/span><strong>26. What is the difference between a sorted collection and an ordered collection?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>As the name indicates sorted collection is based on the elements having order but the order depends on the value of the element such as the sorted set.<\/p>\r\n\r\n\r\n\r\n<p>An ordered collection is the name of elements having a specific order and it is independent of the value such as a list.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id=\"4\"><span class=\"ez-toc-section\" id=\"Core_Interfaces-2\"><\/span><strong>Core Interfaces<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"27_What_are_the_core_interfaces_of_Hibernate\"><\/span><strong>27. What are the core interfaces of Hibernate?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Following are the core interfaces of the hibernate framework:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Configuration<\/li>\r\n<li>SessionFactory<\/li>\r\n<li>Session<\/li>\r\n<li>Query<\/li>\r\n<li>Criteria<\/li>\r\n<li>Transaction<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"28_What_is_a_Hibernate_Session\"><\/span><strong>28. What is a Hibernate Session?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>A hibernate session is a runtime interface that is used between the application and hibernates. In simple words, it establishes a connection between the application and the database to perform different functions such as create, delete, get, and update.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"29_Is_the_session_thread-safe\"><\/span><strong>29. Is the session thread-safe?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>No, it is not a thread-safe object because it can be accessed by multiple threads.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"30_What_is_a_difference_between_openSession_and_getCurrentSession\"><\/span><strong>30. What is a difference between openSession() and getCurrentSession()?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>SessionFactory.openSession creates a new session object and gives it to you for performing different operations. But keep in mind, you need to close these session objects because these are not thread-safe. If you have a multithreaded environment then you need to create one session per request. Moreover, one session per request is also used in web applications.<\/p>\r\n\r\n\r\n\r\n<p>SessionFactory.getCurrentSession creates a new session if not exist otherwise it will use the same session. The object provided by the getCurrentSession is managed internally and automatically closes the session when a transaction ends, so there is no need to manage it externally.\u00a0<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"31_What_is_SessionFactory\"><\/span><strong>31. What is SessionFactory?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>SessionFactory can be created by providing a configuration object and it is an interface that contains all DB-related property details pulled by hibernate.properties or hibernate.cfg.xml. In short, it is a factory for session objects that is created during application start-up and kept for later use because it is a heavyweight object.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"32_Is_SessionFactory_thread-safe\"><\/span><strong>32. Is SessionFactory thread-safe?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Yes, many threats cannot access it at the same time.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id=\"5\"><span class=\"ez-toc-section\" id=\"Data_Manipulation-2\"><\/span><strong>Data Manipulation<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"33_What_is_eager_loading_in_Hibernate\"><\/span><strong>33. What is eager loading in Hibernate?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Eager loading is a design pattern in which the data initialization phase is completed on the spot and it is considered the best option when the relations are not too much. It is the best practice to reduce the further queries on the <a class=\"aioseop-link\" href=\"https:\/\/www.temok.com\/dedicated-servers-usa\" target=\"_blank\" rel=\"noopener\">server<\/a>.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"34_What_is_lazy_loading_in_Hibernate\"><\/span><strong>34. What is lazy loading in Hibernate?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Lazy loading means whenever the select query is executed it will not directly access the database and wait for the function i.e. when we need then it will fetch from the database.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"35_What_is_a_lazy_initialization\"><\/span><strong>35. What is a lazy initialization?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Lazy initialization or lazy fetching is the opposite of eager and it means when a record is loaded for the database the child rows ( in case of too many relationships) are not loaded.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"36_What_is_cascading_in_hibernate\"><\/span><strong>36. What is cascading in hibernate? <\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>It is about persistent actions involving an object propagating to other objects with the help of association. Cascading can apply to a range of hibernate actions and it is characteristically transitive.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"37_What_is_the_key_difference_between_merge_and_update_methods\"><\/span><strong>37. What is the key difference between merge() and update() methods?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Merge() is used to synchronize all data changes such as removal and addition of row but update can only modify column values.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"38_What_is_the_main_difference_between_save_and_persist_methods\"><\/span><strong>38. What is the main difference between save() and persist() methods?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>The persist () method is similar to the save method that is also used to INSERT the records in the database but it has a void return type whereas the save has the return type of Serializable Object.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"39_What_is_the_N1_problem\"><\/span><strong>39. What is the N+1 problem?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>It is a problem that happens when the data access framework executes N additional SQL statements to fetch the same data that could have been accessed when executing primary SQL statements\/queries. The larger the value of N the more queries will be executed and have a great performance impact.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"40_What_is_a_Named_Query\"><\/span><strong>40. What is a Named Query?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>The named query is the name of a predefined unchangeable query string which is similar to alias names. It can be defined by a mapping file or annotation.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"41_What_is_the_key_benefit_of_Hibernate_Criteria_API\"><\/span><strong>41. What is the key benefit of Hibernate Criteria API?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>The main benefit of hibernate criteria API is that it is dedicatedly designed to manipulate data without any hard-coded SQL statements.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id=\"6\"><span class=\"ez-toc-section\" id=\"Transaction_Management-2\"><\/span><strong>Transaction Management<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"42_What_is_a_transaction\"><\/span><strong>42. What is a transaction?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>A transaction is an event that represents a unit of work that can be described by ACID properties (Atomicity, Consistency, Isolation, and Durability). So, if one step fails, the whole transaction fails which is known as atomicity.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"43_What_is_transaction_propagation\"><\/span><strong>43. What is transaction propagation?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Transaction propagation shows if any component will or will not participate in any particular transaction and how will it behave if the calling service or component already has or does not have a transaction created already.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"44_Enlist_the_hibernate_isolation_levels\"><\/span><strong>44. Enlist the hibernate isolation levels.<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Following are the Hibernate isolation levels: READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"45_What_is_the_difference_between_an_optimistic_lock_and_a_pessimistic_lock\"><\/span><strong>45. What is the difference between an optimistic lock and a pessimistic lock?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Before committing the transaction, optimistic locking is used when you check if the record was updated by someone else. In the case of pessimistic locking, you take an exclusive lock so that you can make sure no one else can modify the record.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id=\"7\"><span class=\"ez-toc-section\" id=\"Cache_Management-2\"><\/span><strong>Cache Management<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"46_How_many_cache_levels_do_you_know_in_Hibernate\"><\/span><strong>46. How many cache levels do you know in Hibernate?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>Two caching levels exist in the hibernate: first-level cache and second-level cache. In the first level cache, objects are cached within the current session and only alive until a session is closed but the second level cache exists as long as the SessionFactory is alive.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"47_What_is_the_1st_level_cache\"><\/span><strong>47. What is the 1st level cache?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>The first level cache provides the session level in the process caching. Once the session is created, a session cache is associated with it and the copy of a session cache is maintained when an object is loaded in from the database.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"48_Is_it_possible_to_disable_1st_level_cache\"><\/span><strong>48. Is it possible to disable 1st level cache?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>No, you cannot disable the 1<sup>st<\/sup> level cache.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"49_What_is_the_2nd_level_cache\"><\/span><strong>49. What is the 2nd level cache?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>2<sup>nd<\/sup> level cache is a store of entity data managed by the persistence provider to improve the performance of the application by avoiding expensive database calls and keeping the entity data local to the application.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"50_What_is_the_difference_between_1st_and_2nd_levels_of_cache\"><\/span><strong>50. What is the difference between 1st and 2nd levels of cache?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>The main difference is that 1<sup>st<\/sup> level cache is maintained at the session level while the 2<sup>nd<\/sup> level cache is maintained at SessionFactory. The data stored in the first level cache is only accessible to the session who maintains it while the second level cache is accessible to all.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"51_How_to_clear_cache\"><\/span><strong>51. How to clear cache?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<p>You can use the session evict() method to remove a single object from the first-level cache but if you want to delete all the objects from the cache then session clear() is used for this purpose.<\/p>\r\n\r\n\r\n\r\n<p>That\u2019s all for Hibernate Interview Questions and Answers, I hope it will help both beginners and experienced people. Moreover, take a look at compulsory things including industry research, reasons you want the job, preparation for common interview questions, practice, practice, and practice. Moreover, you can also prepare <a class=\"aioseop-link\" href=\"https:\/\/www.blog.temok.com\/sql-interview-questions-and-answers\/\" target=\"_blank\" rel=\"noopener\">100+ SQL Interview Questions and Answers<\/a> to understand the database concepts.<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p><span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><\/span> <span class=\"rt-time\"> 11<\/span> <span class=\"rt-label rt-postfix\">min read<\/span><\/span>Hibernate is a popular ORM tool that is used in enterprise applications for database-related operations and other Java applications. Therefore, top companies are looking for hibernate experts for their day-to-day operations. So, I have decided to write an article on the hibernate interview questions and answers which is mandatory to polish your knowledge before the [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":6333,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"pmpro_default_level":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[442],"tags":[757,759,2946,758],"class_list":["post-6329","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technical-interviews","tag-hibernate","tag-hibernate-framework-interview-questions-and-asnsers","tag-hibernate-interview-questions-and-answers","tag-top-hibernate-interview-questions","pmpro-has-access"],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2020\/11\/blg1.jpg?fit=750%2C500&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/posts\/6329","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/comments?post=6329"}],"version-history":[{"count":12,"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/posts\/6329\/revisions"}],"predecessor-version":[{"id":13179,"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/posts\/6329\/revisions\/13179"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/media\/6333"}],"wp:attachment":[{"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/media?parent=6329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/categories?post=6329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/tags?post=6329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}