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 file.it will be describe inside hbm.xml file.
• There we are declare property name, class name and type of variable.
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;
@Entity
@Table(name="Employee")
public class Employee {
@Id
@GeneratedValue
@Column(name="Id")
private int id;
@Column(name="firstName")
private String firstname;
@Column(name="lastName")
private String lastname;
@Column(name="Salary")
private int salary;