Providing an annotation-based hibernate mapping

When we choose the annotation-based way to provide a configuration, we don't need to create any hibernate mapping (usually *.hbm. xml) file. Hibernate provides the annotations that we can directly write to the POJO, and we can provide all the mappings via the classes, which we can do using the previous XML file.

How to do it…

Now, let's create the class that contains the annotation-based mapping. As we used the Employee class to provide XML-based mapping here, we will use the same class with annotations:

  1. Represent the annotation-based mapping for the Employee class in Employee.java, as shown in the following code:
    import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; ...

Get Java Hibernate Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.