Integrate ZK5 with Spring 3 and Hibernate"

From Documentation
Line 18: Line 18:
 
:If you have installed ZK Studio plugin in Eclispe, refer [http://books.zkoss.org/wiki/ZK_Installation_Guide/Quick_Start/Create_and_Run_Your_First_ZK_Application_with_Eclipse_and_ZK_Studio here] for create a simple ZK project.
 
:If you have installed ZK Studio plugin in Eclispe, refer [http://books.zkoss.org/wiki/ZK_Installation_Guide/Quick_Start/Create_and_Run_Your_First_ZK_Application_with_Eclipse_and_ZK_Studio here] for create a simple ZK project.
 
<li>Add Spring 3.0.6 jar files</li>
 
<li>Add Spring 3.0.6 jar files</li>
:Download jar files from [http://www.springsource.org/spring-core SpringSource Community]
+
:Download jar files from [http://www.springsource.org/spring-core SpringSource Community] and copy the following jar files into WEB-INF/lib directory.
 
:[[image:spring_jar.jpg]]
 
:[[image:spring_jar.jpg]]
 
<li>Add Spring 3.0.6 jar files</li>
 
<li>Add Spring 3.0.6 jar files</li>
:Download jar files from [http://www.hibernate.org/downloads.html Hibernate]
+
:Download jar files from [http://www.hibernate.org/downloads.html Hibernate] and copy the following jar files into WEB-INF/lib directory.
 
:[[image:hibernate_jar.jpg]]
 
:[[image:hibernate_jar.jpg]]
 
</ul>
 
</ul>
 +
 
==By Maven==
 
==By Maven==
 
<ul>
 
<ul>

Revision as of 07:41, 7 December 2011

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