Create the XML files.
UserDetails.hbm.xml
[xml]
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.splessons.UserDetails" table="LoginUserDetails" >
<id name="id">
<generator class="increment"></generator>
</id>
<property name="username"/>
<property name="password"/>
<property name="email"/>
</class>
</hibernate-mapping>
[/xml]
The subelement of id used to generate the unique identifier for the objects of persistent class, increment generates the unique id only if no other process is inserting data into this table. It generates short, int or long type identifier.
hibernate.cfg.xml
[xml]
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
//Database connection properties
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver
</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:xe
</property>
<property name="connection.username">system</property>
<property name="connection.password">system</property>
//hibernate properties
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="hbm2ddl.auto">create</property>
<property name="show_sql">true</property>
//mapping file properties
<mapping resource="UserDetails.hbm.xml"/>
</session-factory>
</hibernate-configuration>
[/xml]
Properties |
Description |
hibernate.connection.driver_class |
The JDBC driver class. |
hibernate.dialect |
This property makes Hibernate generate the suitable SQL for the picked database. |
hibernate.connection.url |
The JDBC URL to the database instance. |
hibernate.connection.username |
The database username. |
hibernate.connection.password |
The database password. |
hibernate.connection.pool_size |
Limits the number of connections waiting in the Hibernate database connection pool. |
hibernate.connection.autocommit |
Allows autocommit mode to be used for the JDBC connection. |
The configuration file will consist of connection properties, hibernate properties, mapping file name will consist of all the related class names. Dialect classes are used to convert HQL statements to database specific statements. To connect any database with hibernate, We need to specify the database Dialect class in hibernate. cfg. xml. If a show_sql value is true, generated the SQL statements in a console.
struts.xml
[xml]
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation //DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="Login" class="com.splessons.UserDetails">
<result name="success">success.jsp</result>
</action>
</package>
</struts>
[/xml]
web.xml
[xml]
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Struts 2</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>
/*
</url-pattern>
</filter-mapping>
</web-app>
[/xml]