Home Struts Hibernate-spring Writing Java Object (POJO)



Writing Java Object (POJO)
Posted on: January 8, 2008 at 12:00 AM
System authenticates the user against the database and if the credentials provided by user are correct then user is allowed to login to the system, otherwise appropriate message is displayed.

Writing Java Object (POJO)

     

In the tutorial we are developing web application that will enable the new users to register online. Existing users can logon to the system. System authenticates the user against the database and if the credentials provided by user are correct then user is allowed to login to the system, otherwise appropriate message is displayed.

Hibernate Mapping Class

We have only one table into the database and we need one POJO class and the hibernate mapping file to map the login object to the database table. Here is the code for "Login.hbm.xml" mapping file:

 

 

 

<?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

  <hibernate-mapping auto-import="true" default-lazy="false">

  <class  name="roseindia.dao.hibernate.Login"  table="login" >

  <id  name="id"
  type="java.lang.Integer"
  column="id"
  >
   <generator class="increment" />
  </id>

  <property
  name="loginid"
  type="java.lang.String"
  column="loginid"
  not-null="true"
  unique="true"
  length="20"
  />

  <property
  name="password"
  type="java.lang.String"
  column="password"
  not-null="true"
  length="20"
  />

   <property
  name="email"
  type="java.lang.String"
  column="email"
  not-null="false"
  length="30"
  />

  <property
  name="address"
  type="java.lang.String"
  column="address"
  not-null="false"
  length="60"
  />

  

  <property
  name="phno"
  type="int"
  column="phno"
  not-null="false"
  length="11"
  />

  
  </class>
  </hibernate-mapping>

Above file should be present in the project\WEB-INF\src\java\roseindia\dao\hibernate directory. 

POJO Class
Here is the code of Login.java POJO class:

package roseindia.dao.hibernate;

import java.io.Serializable;

public class Login implements Serializable {

  /** identifier field */
  private Integer id;

  /** persistent field */
  private String loginid;

  /** persistent field */
  private String password;
  
  /** persistent field */
  private String email;
  
  
  /** persistent field */
  private String address;
  
  
  /** persistent field */
  private int phno;

  /** full constructor */
  public Login(Integer id, String loginid, 

String password, String email, 

String address, int phno) {
  this.id = id;
  this.loginid = loginid;
  this.password = password;
  this.address = address;
  this.phno = phno;
  this.email = email;
  }

  /** default constructor */
  public Login() {
  }

  public Integer getId() {
  return this.id;
  }

  public void setId(Integer id) {
  this.id = id;
  }

  public String getLoginid() {
  return this.loginid;
  }

  public void setLoginid(String loginid) {
  this.loginid = loginid;
  }

  public String getPassword() {
  return this.password;
  }

  public void setPassword(String password) {
  this.password = password;
  }

  public String getAddress() {
  return address;
  }

  public void setAddress(String address) {
  this.address = address;
  }

  public String getEmail() {
  return email;
  }

  public void setEmail(String email) {
  this.email = email;
  }

  public int getPhno() {
  return phno;
  }

  public void setPhno(int phno) {
  this.phno = phno;
  }

}

 Save the above code into project\WEB-INF\src\java\roseindia\dao\hibernate directory.

In this section we developed the POJO class and the mapping file for our project.

Related Tags for Writing Java Object (POJO):
cdatabasehibernatewebfileclasstabledataapplicationloginobjectmappingiomapusersystemgisuserstutorialnewintlinerialogonlineapptabpingnattopojobaseregistereillogoenablecanliusedevinasmntsticajclemasepiintoobjppcatsystorseeginatpinishallgogistdevelopdevelopingexistingandartutorxissrithavstabablatiaphatexijeicaicaplppindonlyononl


More Tutorials from this section

Ask Questions?    Discuss: Writing Java Object (POJO)   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.