Mapping files in Hibernate
Mapping files in Hibernate
Ordinarily, object-relational mappings are defined in an XML file. Which database tables should be mapped to the classes defined in this file?
The mapping document can be generated by several tools, while many Hibernate users prefer to write it by hand. For expert Hibernate users, they include XDoclet, Middlegen, and AndroMDA.
Here are the mapping elements which are used in the mapping file –
- As the document's root element, hibernate mapping contains all the elements.
- In the element, mappings between Java classes and database tables are defined. The name of the Java class is supplied using the class element's name attribute, and the name of the database table is specified using the table element's table attribute.
- Class descriptions can be created using the element, which is optional.
- It translates the class's unique ID attribute to the primary key of the database table using the element. Its name attribute corresponds to a class property, whereas its column attribute refers to a database table column. In the hibernate mapping type attribute, Java data types are converted to SQL data types by hibernating.
- Generate the main key values with ease by inserting the id element's element inside it. Depending on the underlying database's capabilities, the generator element's class attribute has been set to native.
- This element maps a Java class's property to a column in the database table using the property attribute. The element's name relates to a class property, whereas a column refers to a data table column. In the hibernate mapping type attribute, Java data types are converted to SQL data types by hibernating.