Integrate ZK5 with Spring 3 and Hibernate

From Documentation
DocumentationSmall Talks2011DecemberIntegrate ZK5 with Spring 3 and Hibernate
Integrate ZK5 with Spring 3 and Hibernate

Author
Vincent Jian, Engineer, Potix Corporation
Date
December 12, 2011
Version
ZK5+, Spring 3, Hibernate 3.6

WarningTriangle-32x32.png This page is under construction, so we cannot guarantee the accuracy of the content!

Introduction

Fernando De Leon introduced how to integrate ZK2.1.1, Spring and Hibernate. Since ZK have great improvement from version 2 to version 5, this document will demonstrate how to integrate ZK 5.0.x, Spring 3.0 and Hibernate 3.6 with a sample project that connect to MySQL database step by step.

Step 1: MySQL Database Schema

First we create a database in MySQL called support with two tables, company and contact. Here company and contact has one-to-many relationship. Database schema.jpg

Step 2: Create a Web Application Project

By ZK Studio

  • Create a ZK project
  • If you have installed ZK Studio plugin in Eclispe, refer here to create a simple ZK project.
  • Add Spring 3.0.6 jar files
  • Download jar files from SpringSource Community and copy the following jar files into WEB-INF/lib directory.
    Spring jar.jpg
  • Add Spring 3.0.6 jar files
  • Download jar files from Hibernate and copy the following jar files into WEB-INF/lib directory.
    Hibernate jar.jpg

By Maven

  • Create a Maven Project
  • If you prefer to using maven, refer here to create a ZK project with maven.
  • Modify the pom.xml file to add Spring and Hibernate jar files.
  • a) Add version properties and repositories of Spring and Hibernate.
    <properties>
    	<zk.version>5.0.9</zk.version>
    	<org.springframework.version>3.0.6.RELEASE</org.springframework.version>
    	<hibernate.version>3.6.8.Final</hibernate.version>
    </properties>
    ...
    <repository>
    	<id>repository.springframework.maven.release</id>
    	<name>Spring Framework Maven Release Repository</name>
    	<url>http://maven.springframework.org/release</url>
    </repository>
    <repository>
    	<id>Hibernate repository</id>
    	<url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url>
    </repository>
    
    b) Add dependencies of Spring and Hibernate
    <!-- Spring dependency -->
    <dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-core</artifactId>
    	<version>${org.springframework.version}</version>
    </dependency>
    <dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-orm</artifactId>
    	<version>${org.springframework.version}</version>
    </dependency>
    <dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-web</artifactId>
    	<version>${org.springframework.version}</version>
    </dependency>
    <!-- Hibernate dependency -->
    <dependency>
    	<groupId>org.hibernate</groupId>
    	<artifactId>hibernate-core</artifactId>
    	<version>${hibernate.version}</version>
    </dependency>
    <dependency>
    	<groupId>org.hibernate</groupId>
    	<artifactId>hibernate-entitymanager</artifactId>
    	<version>${hibernate.version}</version>
    </dependency>
    <dependency>
    	<groupId>org.hibernate</groupId>
    	<artifactId>hibernate-c3p0</artifactId>
    	<version>${hibernate.version}</version>
    </dependency>
    <!-- MySql dependency start -->
    <dependency>
    	<groupId>mysql</groupId>
    	<artifactId>mysql-connector-java</artifactId>
    	<version>5.1.18</version>
    </dependency>
    

Step 3: Configure Hibernate and Spring

Step 4: Implement User Interfaces with ZK

Summary

Comments



Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.