Creating a hibernate persistent class
As discussed in the Preface, the developer will be dealing with objects at every step of development. Also, when we use hibernate, we don't need to work on a core SQL query. Here, we will create a POJO (Plain Old Java Object) in Java, which represents a table in the database.
Getting ready
By POJO, we mean that we will create a Java class that satisfies the following requirements:
- It needs to have a default constructor that is persistent.
- It should contain the
id
attribute. ID is used to identify the object and is mapped with the primary column of a table. - All attributes should have
Getter
andSetter
methods, such asgetXXX
andsetXXX
wherexxx
is a field name.
How to do it...
We will now create a persistent class ...
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.