Hibernate - SPLessons

Hibernate Mapping

Chapter 5

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Hibernate Mapping

Hibernate Mapping

shape Description

Hibernate Mapping is a system utilized to educate ORM device about recognizable proof of POJO classes put away in tables. Mapping is a procedure to outline a POJO class name and table name furthermore to delineate class variables and the table segment names.

Hibernate Mapping is Metadata, not an information. Thus, from the mapping documents, hibernate peruses the information and stores in the Database. Each ORM needs the mapping data. Hibernate can store the condition of Object in the Database.

shape Conceptual

All POJO class Objects will map to the Hibernate. Then Hibernate takes the data from POJO class and then maps into a table.

shape Conceptual

Really our POJO class object having 3 states like. Transient state, Persistent state, Detached state. At whatever point an object of a pojo class is made then it will be in the Transient state, When the object is in a Transient state it doesn’t speak to any row of the database, i mean not connected with any Session object, in the event that we talk more we can say no connection with the database its only a typical item. In the event that we change the information of a pojo class object, when it is in transient state then it doesn’t impact on the database table, When the item is in persistent state, then it speak to one row of the database, if the object is in persistent state then it is connected with the unique Session.

Hibernate Mapping using XML file

shape Description

Hibernate maps Pojo class name to Table. If Class name and Table name are same, writing XML in table name is optional and if Variable name and Table Column name are same mapping file Column name is Optional. All XML files are extended to . Xml but, in hibernate mapping, the file name is extended to Xxx .hbm.xml. Following is the syntax of writing a mapping file in Hibernate.

<div class="crayon-line" id="crayon-575c2fd7819be894077258-1">
<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" />


shape Key Points

  • Hibernate may have more mapping files.
  • Hibernate application needs mapping file and configuration file.
  • Java class property will be mapped to column in data base by using the property tag.