Java class are mapped to columns of a DB table in Hibernate

There are two way we can mapped to columns of a DB table to the properties of a Java class in Hibernate.
Using the XML file :-
   We can map the column of a table to the property of a class in XML will be describe inside hbm.xml file.
    There we are declare property name, class name and type of variable.

					<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
 "-//Hibernate/Hibernate Mapping DTD//EN"

	<class name="com.Employee" table="Employee">
		<id name="id" type="int" column="id">
			<generator class="native" />
		<property name="firstname" column="firstname" type="string" />
		<property name="lastname" column="lastname" type="string" />
		<property name="salary" column="salary" type="int" />

Using annotations :-

  • There we are use annotations @Entity, @Table and @Column to map a column to the property of a class.
  • we are use @Column to explicitly define the column name that is mapped to the a property.
  • If no @Column is used then it will use the configured naming strategies to determine which column should a property mapped to.
					import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

public class Employee {
private int id;

private String firstname;

private String lastname;

private int salary;