InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
Is hibernate prone to SQL injection attack? |
|
Answer» SQL INJECTION attack is a serious vulnerability in terms of web security wherein an attacker can interfere with the queries made by an application/website to its DATABASE thereby allowing the attacker to view sensitive data which are generally irretrievable. It can also give the attacker to modify/ remove the data RESULTING in damages to the application behavior. Hibernate does not provide immunity to SQL Injection. However, following good practices avoids SQL injection attacks. It is always advisable to follow any of the below options:
|
|
| 2. |
Can you explain the concept behind Hibernate Inheritance Mapping? |
|
Answer» Java is an Object-Oriented Programming Language and INHERITANCE is one of the most important pillars of object-oriented principles. To represent any models in Java, inheritance is most commonly used to simplify and simplify the relationship. But, there is a catch. Relational databases do not SUPPORT inheritance. They have a flat structure. Hibernate’s Inheritance Mapping strategies deal with solving how to hibernate being an ORM tries to map this problem between the inheritance of Java and flat structure of Databases. Consider the example where we have to divide InterviewBitEmployee into CONTRACT and Permanent Employees represented by IBContractEmployee and IBPermanentEmployee classes respectively. Now the task of hibernate is to represent these 2 employee types by CONSIDERING the below restrictions: The general employee details are defined in the parent InterviewBitEmployee class. Contract and Permanent employee-specific details are stored in IBContractEmployee and IBPermanentEmployee classes respectively The class diagram of this system is as shown below: Hibernate’s Inheritance Mapping
There are different inheritance mapping strategies available:
|
|
| 3. |
How do you create an immutable class in hibernate? |
|
Answer» Immutable class in hibernate creation could be in the following way. If we are using the XML FORM of configuration, then a class can be made immutable by markingmutable=false. The default value is TRUE there which indicating that the class was not created by default. In the CASE of using annotations, immutable classes in hibernate can also be created by using @Immutable ANNOTATION. |
|
| 4. |
What can you tell about Hibernate Configuration File? |
|
Answer» Hibernate Configuration File or hibernate.cfg.xml is ONE of the most required configuration files in Hibernate. By default, this file is placed under the src/main/resource folder. This file is used to define the below information:
|
|
| 5. |
What is the difference between first level cache and second level cache? |
||||||||
|
Answer» Hibernate has 2 cache types. First level and second level cache for which the difference is given below:
If an entity or object is loaded by CALLING the get() method then Hibernate first checked the first level cache, if it doesn’t find the object then it goes to the second level cache if CONFIGURED. If the object is not found then it finally goes to the database and returns the object, if there is no corresponding row in the table then it returns null. |
|||||||||
| 6. |
Can you explain what is lazy loading in hibernate? |
|
Answer» Lazy LOADING is mainly used for IMPROVING the application performance by HELPING to load the child objects on demand. It is to be noted that, since Hibernate 3 version, this feature has been ENABLED by default. This signifies that child objects are not loaded until the parent gets loaded. |
|
| 7. |
What do you think about the statement - “session being a thread-safe object”? |
|
Answer» No, Session is not a thread-safe object which means that any NUMBER of threads can access DATA from it SIMULTANEOUSLY. |
|
| 8. |
What is a SessionFactory? |
|
Answer» SessionFactory provides an instance of Session. It is a factory class that gives the Session objects based on the CONFIGURATION PARAMETERS in order to establish the connection to the database. This also provides the facility to get information LIKE statistics and metadata related to a class, query executions, etc. It also holds second-level cache data if ENABLED. |
|
| 9. |
What is a Session in Hibernate? |
|
Answer» A SESSION is an OBJECT that maintains the connection between Java object application and database. Session also has METHODS for storing, retrieving, modifying or deleting data from database using methods like persist(), load(), get(), UPDATE(), delete(), etc. Additionally, It has factory methods to return Query, Criteria, and Transaction objects. |
|
| 10. |
What are some of the important interfaces of Hibernate framework? |
|
Answer» HIBERNATE CORE INTERFACES are:
|
|
| 11. |
What are the advantages of Hibernate over JDBC? |
|
Answer» - The ADVANTAGES of Hibernate over JDBC are listed below:
|
|
| 12. |
What is ORM in Hibernate? |
|
Answer» Hibernate ORM STANDS for Object Relational Mapping. This is a mapping tool pattern mainly USED for converting data stored in a relational DATABASE to an object used in object-oriented programming constructs. This tool also helps GREATLY in simplifying data retrieval, CREATION, and manipulation. Object Relational Mapping |
|