Hibernate - Create POJO Classes Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 1 Likes Like Report POJO stands for Plain Old Java Object. In simple terms, we use POJO to make a programming model for declaring object entities. The classes are simple to use and do not have any restrictions as compared to Java Beans. To read about POJO classes and Java Bean refer to the following article - POJO classes and Java Bean POJO is handier as its best in readability and reusability. The only difference between java bean and POJO classes is POJOs don't have any restrictions other than java but java beans have. Properties of POJO classesThe POJO classes must be public so that we can use them outside the class.POJO does not have any name convention for properties and methods. It's just a java class consisting of some variables and getters-setters.POJO classes are used in hibernate for mapping to database objects. That means all object entities we make in POJO classes will be reflected in a database object.It should not extend classes, implement interfaces, or contain prespecified annotations. Also, it does not bound with any restrictions but strictly follows java language specifications.In hibernate, POJOs also contain some annotations like @Entity, @Table, @id, etc for avoiding XML files for database objects.Working with POJO classes POJO classes are used to encapsulate business logic and its members are treated as a database entity. The main motive of POJO classes is to define an object entity for hibernating. Implementation: Let us make an employee POJO class A. File: Employee.java Java // Java Program to Illustrate Employee Class // POJO class // Importing required classes import java.io.*; // Class class Employee { // Private variables which are treated as an entity private int empid; private String name; private int age; // Getters and setters // Getter public int getEmpid() { return empid; } // Setter public void setEmpid(int empid) { this.empid = empid; } // Getter public String getName() { return name; } // Setter public void setName(String name) { this.name = name; } // Getter public int getAge() { return age; } // Setter public void setAge(int age) { this.age = age; } } Let's make a POJO class method and use them to set and get the data. B. File: MainClass.java Java // Importing required classes import java.io.*; // Main class class MainClass { // Main driver method public static void main(String[] args) { // Making a POJO class method to // set and retrieve some values employee emp = new employee(); // Setting the values with setters emp.setEmpid(123); emp.setName("Geek"); emp.setAge(21); // Retrieving some values from getters System.out.println("The employee ID is " + emp.getEmpid()); System.out.println("The name of the employee is " + emp.getName()); System.out.println("The age of the employee is " + emp.getAge()); } } Output: Create Quiz Comment S shiv_ka_ansh Follow 1 Improve S shiv_ka_ansh Follow 1 Improve Article Tags : Java Geeks Premier League Geeks-Premier-League-2022 Java-Hibernate Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References7 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers1 min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like