InterviewSolution
| 1. |
Explain Hibernate configuration file and Hibernate mapping file? |
|
Answer» Hibernate configuration file: This file CONTAINS a set of configuration settings related to the database and other related parameters which is required by Hibernate for connecting to the database. This file is placed in the root directory of the application’s classpath. Some properties that are configured in this file are:
Hibernate Mapping file: This file contains the mapping of a POJO class to the table. Giving the POJO class the same name as the table and having class properties corresponding to the column names helps in avoiding confusions while mapping the class properties to the table columns.An object normally contains 3 properties - identity, state and behavior. The identity and behavior of the object has to be avoided when storing the object state (value) in the database. This is TAKEN care of by mapping. A Hibernate application can have multiple mapping files for mapping the classes to the tables.Mapping can be done using XML or Annotations. Syntax for creating a mapping file in XML is as below: <hibernate-mapping> <class name="POJO class name" table="table name in database"> <ID name="VARIABLE name" column="column name in database" type="java/hibernate type" /> <property name="variable1 name" column="column name in database" type="java/hibernate type" /> <property name="variable2 name" column="column name in database" type="java/hibernate type" /> </class> <hibernate-mapping> |
|