1.

What are POJOs and what is their use?

Answer»

POJO stands for Plain Old JAVA Object. Hibernate is based on the concept of taking values from Java class attributes and storing them in a database. Such classes whose OBJECTS are stored in a database are known as persistent classes. These classes have proper getter and setter methods for every PROPERTY. These classes also have a default constructor. These classes should be non-final or have an interface with all the public methods declared. An ID is mandatory for each object of these classes as they will be mapped to the primary column of the table. Use of POJOs instead of simple java classes results in an efficient and well – CONSTRUCTED code. A simple example of a POJO class is as below:

public class Student{  private int id;  private String firstName;  private String lastName;  private int age;  public Employee(){}  public Employee(String fname,String lname,int age){  this.firstName=fname;  this.lastName=lname;  this.age= age;  }  public int getId(){return id; }  public void setId(int id ){ this.id = id;}  public String getFirstName(){ return firstName;}  public void setFirstName(String first_name){   this.firstName=first_name;  }  public String getLastName(){ return lastName; }  public void setLastName(String last_name){   this.lastName=last_name;  }  public int getAge(){ return age; }  public void setAge(int age ){ this.age= age; }  }


Discussion

No Comment Found