Mapping can also be achieved using annotations. Instead of writing the mapping file Employee.hbm.xml, we can directly define the mapping in the 'Employee' class itself using Annotations.
Let us see below how we can map the 'Employee' class:
The above code is almost same as the above :
We have put '@Entity' just above 'class Employee', which tells Hibernate that 'Employee' class needs to be treated as an 'Entity' and should be saved to a table named 'EMPLOYEE'.
Next, we have @Id annotation above 'int empId'. Which tells Hibernate that 'empId' should be treated as a primary key and the column name in the database would be 'EMP_ID'.
Finally, we have the @Column annotation which tells Hibernate that the 'name' field should be treated as a column and should be named as 'NAME' on the database side.