In order to use annotations for mapping in Hibernate we need to annotate our persistent classes. We’ll be replacing the XML mapping configuration with annotations. Let’s reuse the code we have already done in this post. We’ll remove the message.hbm.xml and add annotation to the Message class for mapping. Here’s the listing for Message class.

and for the same, we’ll have to edit the hibernate.cfg.xml to add the annotated class to the Hibernate configuration.