Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
 
 
Search All Tutorials

 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 
Struts
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

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.

                         

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

2 comments so far (post your own) View All Comments Latest 10 Comments:

Hi,
i am getting an error called "Exception creating bean of class roseindia.web.struts.form.EventsForm: {1}" while i am trying to add a form more to the application.

I've modified struts-config.xml,Login.hbm.xml,appli...xml,created one form class, one action class, added two methods called "addevents()" "loadevents()" to the "dao" package.

How can i resolve the error?

Posted by krishna on Saturday, 06.23.07 @ 23:18pm | #20058

Hi Deepak,

What changes need to be done in application context and other necessary files if we need to use org.springframework.orm.hibernate3.support.HibernateDaoSupport; instead of org.springframework.orm.hibernate.support.HibernateDaoSupport;

Posted by Akash Borkar on Thursday, 03.15.07 @ 22:45pm | #11837

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Hot Web Programming Job

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.