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:
|
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.