Friday, July 17, 2015

What is Hibernate Mapping or hbm.xml ?

Hibernate Mapping or hbm.xml : – Hibernate Mapping or hbm.xml file allow you to map the persistent object in the form of XML file.
So if you are a beginner than you might have confused with the above statement but do not worry please follow below points : -
In my Previous Post we have seen the a sample Hibernate java exmaple so we will take the same one.
Database Table Name : – Person
IDFIRST_NAMELAST_NAME
1  RAHUL WAGH
Hibernate Mapping FIle : -


    
      
        
            
        
          
        
              
        
          
    


JAVA POJO Class :  -
package com.hibernate.enity;
  
public class Person {
      
    private int id;
    private String firstName;
    private String lastName;
      
      
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
      
      
}
  • : – What ever mapping you are doing we need to write in between these two tags.
  • : – Here you will mention the POJO class which you have created for the person. In the name=" " you need to specify the complete path of the calss and in table=" " you need to specify the table name
  • : – In this tag specify the primary key of your database table
  • : – You can specify the column name of the database table and corresponding member of the pojo class .(In this case column_name="first_name" and pojo member is name="firstName")
There are so many attributes associated with the each mapping tags so you can use them according to your application or project need. Please see below for additional tags : -

CLASS : -

Please post you comments and suggestions below ……

No comments:

Post a Comment