This is a very simple tutorial explaining the use of Tapestry-Hibernate module. You can find the official documentation here:
you can download example project (tested in Eclipse with mvneclipse)

First I will assume that you have properly set up Tapestry, Hibernate-core, Hibernate-Annotation, MySQL in your system.

Following are steps:

Step 1:

Create a working Tapestry project, you can follow the examples in the or simply does the following:

mvn archetype:create  -DarchetypeGroupId=org.apache.tapestry -DarchetypeArtifactId=quickstart  -DarchetypeVersion=5.0.5 -DgroupId=org.example -DartifactId=hb -DpackageName=org.example.hb       

cd hb

mvn jetty:run

open http://localhost:8080/hb/ in your browser, if you see 'hb Start Page' then proceed to step 2 otherwise fix the problems first. (if you want another port use: mvn -Djetty.port=8080 jetty:run )

Step 2:

Switch to an IDE and import the maven project, if you are using Intellij you can use following command: mvn idea:idea

open the project under your IDE and create a package under org.example.hb, name it 'entities', then create a under it, copy the following source into

package org.example.hb.entities;

import javax.persistence.*;

public class Hello {

    private long id;
    private String message;

    public long getId() { return id;}

    private void setId(long id) { = id; }

    public String getMessage() { return message;}

    public void setMessage(String message) { this.message = message;}

We can't compile this program yet as we need those hibernate's jar files.

Step 3:

This procedure depends on IDE used, the main goal is to make hibernate jar file available to our project, in my case I create a hibernateLib directory which contains following jar files:

        antlr-2.7.6.jar                         dom4j-1.6.1.jar                         jta.jar
        asm.jar                                 ejb3-persistence.jar                    junit-3.8.1.jar
        c3p0-0.9.1.jar                          hibernate-annotations.jar               log4j-1.2.9.jar
        cglib-2.1.3.jar                         hibernate-commons-annotations.jar       tapestry-core-5.0.5.jar
        commons-codec-1.3.jar                   hibernate3.jar                          tapestry-hibernate-5.0.5.jar
        commons-collections-2.1.1.jar           hsqldb.jar                              tapestry-ioc-5.0.5.jar
        commons-logging-1.0.4.jar                         testng-5.1-jdk15.jar      

if maven is integrated int your IDE (mvneclipse...) just add this to your pom


Step 4:


        <!DOCTYPE hibernate-configuration PUBLIC
                "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
                <property name="hibernate.connection.url">jdbc:mysql://localhost/hb</property>
                <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
                <property name="hibernate.connection.username">root</property>
                <property name="hibernate.connection.password"></property>
                <!-- comment following line during 2nd run -->
               <property name="">create</property>          

                  <!-- pool via c3p0 which knows how to reconnect to server and does it nicely--> 
            <property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
            <property name="hibernate.c3p0.acquire_increment">1</property>
            <property name="hibernate.c3p0.idle_test_period">100</property> <!-- seconds -->
            <property name="hibernate.c3p0.max_size">10</property>
            <property name="hibernate.c3p0.max_statements">0</property>
            <property name="hibernate.c3p0.min_size">1</property>
            <property name="hibernate.c3p0.timeout">100</property> <!-- seconds -->


Step 5:

package org.example.hb.pages;

import java.util.List;

import org.apache.tapestry.annotations.Inject;
import org.example.hb.entities.Hello;
import org.hibernate.Session;

public class HbAction {

    private Session _session;

    private Hello   current;

    public void onAction() {
        Hello h = new Hello();
        h.setMessage("Hello World");;

    public List getList() {
        return _session.createCriteria(Hello.class).list();

    public Hello getCurrent() {
        return current;

    public void setCurrent(Hello current) {
        this.current = current;


Also add HBAction.htm in webapp/WEB-INF/

<html xmlns:t="">
        <title>Hibernate example app</title>
    <t:loop source="list" value="current">


Few more advanced things to do

After this basic setup, we can create a very simple form (BeanEditform is explained at


10/4/2008, added @CommitAfter on the onAction method. Without it, a commit never occurs and the new Hello object is never persisted.

Tapestry5HowToUseTapestryHibernate (last edited 2009-09-20 23:20:45 by localhost)