Hibernate 3 Query Example Part 2

This tutorial explains how to create Hibernate 3 query example with Spring 3 MVC based annotations.


What is difference between Hibernate 4 and 5? Hibernate 5.3 features Hibernate 5 JPA Configuration Hibernate 5 persistence.xml example Hibernate 5 JPA Tutorial Hibernate and JPA Example How properties of a class are mapped to the columns of a database table in Hibernate? Hibernate 5 Annotations Maven dependency Hibernate 5 annotationconfiguration Doctype Hibernate-configuration 5 Hibernate 5 Dialect Hibernate 5 configuration dtd Hibernate 5 Hello World Getting started with Hibernate 5 Hibernate 5.2.10 jar Download Hibernate 5.2.10 Maven Dependency Hibernate 5 Maven Dependency Hibernate 5 native query example Hibernate 5 query deprecated When should you use Hibernate? What's new in Hibernate 5? How much time it takes to learn Hibernate? Hibernate envers custom revinfo table Hibernate 5 Envers Hibernate Envers get all revisions Hibernate Examples Hibernate 5 build SessionFactory Example Hibernate 5 SessionFactory Example Hibernate 5 Annotation Example How to download Hibernate 5.x? Hibernate 5 Features Hibernate 5 Tutorials Learning Hibernate ORM - Free Training/Tutorial videos of Hibernate ORM with Java How to write hello world example program in Hibernate? How to create one to one relationship in Hibernate 4 with Annotation? How to calculate minimum in Hibernate using the min() Function Hibernate ORM 4.2.21.Final Released - Create CURD application in latest Hibernate Hibernate ORM 4.2.21 Tutorial - Learn Hibernate ORM Framework Hibernate Error: Failed to create sessionFactory object.java.lang.NoClassDefFoundError How to create Hibernate Project in Eclipse?

Hibernate 3 Query Example Part 2


Hibernate 3 Query Example Part 2

This tutorial  explains  how to create  Hibernate 3 query example with Spring 3  MVC based annotations. This example is created in ellipse IDE and run in tomcat server.

We will also show you how to run the example from Eclipse IDE and test on Tomcat server. We have also given the screen shot of the example. You can easily download Hibernate 3 Query example and run on your computer.

This example is very helpful for beginners in learning concepts of Hibernate and Spring.

Step 10 :

Now Create "view" folder under "WebContent/WEB-INF" .Again create one jsp file "articlesList.jsp" in "view" folder . The code of  "articlesList.jsp"  given below as :

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>



<title>All Articles</title>



<c:if test="${!empty articles}">

<h1 align="center">List Articles</h1>

<hr width=500 >



<th>Article ID</th>

<th>Article Name</th>

<th>Article Description</th>

<th>Added Date</th>


<c:forEach items="${articles}" var="article">


<td><c:out value="${article.articleId}"/></td>

<td><c:out value="${article.articleName}"/></td>

<td><c:out value="${article.articleDesc}"/></td>

<td><c:out value="${article.addedDate}"/></td>





<c:if test="${empty articles}">

<c:out value="Not Available Article Details"></c:out>




Step 11 :

Now create "searcharticle.jsp" jsp file under "WebContent/WEB-INF/view" directory . The code of  "searcharticle.jsp" given below :

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%@ taglib uri="http://www.springframework.org/tags/form"


<head><title>Add Article</title></head>

<script language="JavaScript">

function Validate(){

var articleid =document.getElementById("articleid").value;

if(articleid=="" || articleid.length<1){

alert( "Please enter article id." );


return false;


if ( isNaN( articleid ) ){

alert( "Please enter a valid article id." );

return false;


return true;




<h1 align="center">Search Article</h1>

<hr width=500 >

<c:url var="viewArticlesUrl" value="/articles.html" />

<br />

<br />

<c:url var="saveArticleUrl" value="/articles/save.html" />

<form:form modelAttribute="article" method="POST"

onsubmit="return Validate();">

<table align="center">


<td><form:label path="articleId">Article Id:</form:label></td>

<td><form:input path="articleId" id="articleid" /></td>

<form:errors path="articleId" > </form:errors>




<td><input type="submit" value="Search" /></td>







Step 12 :

Now open  "web.xml" file  and modify as :

<?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=

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http:
















Step 13 :

Now create "dispatcher-servlet.xml" file  under "WebContent/WEB-INF" directory . The code of  "dispatcher-servlet.xml" given below as :

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"











<context:property-placeholder location="classpath:jdbc.properties" />

<context:component-scan base-package="net.roseindia" />

<tx:annotation-driven transaction-manager="hibernateTransactionManager"/>

<bean id="jspViewResolver"


<property name="viewClass"

value="org.springframework.web.servlet.view.JstlView" />

<property name="prefix" value="/WEB-INF/view/" />

<property name="suffix" value=".jsp" />


<bean id="dataSource"


<property name="driverClassName" value="${database.driver}" />

<property name="url" value="${database.url}" />

<property name="username" value="${database.user}" />

<property name="password" value="${database.password}" />


<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation

<property name="dataSource" ref="dataSource" />

<property name="annotatedClasses">





<property name="hibernateProperties">


<prop key="hibernate.dialect">${hibernate.dialect}</prop>

<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>




<bean id="hibernateTransactionManager"


<property name="sessionFactory" ref="sessionFactory" />



Step 14 :

When run "Hibernate3QueryExample" on tomcat server display output as :


When click hyperlink "List of Articles" display output as :


If click hyperlink "Search Article" then open the search article page as :


If click "Search" Button without entering any number, it displays error message as :


If you enter any invalid number then it displays error message as :


If you enter article id that exists in table, then it displays article details as :


Download Code

Download example code