Monday, 8 April 2013

ZK MVC CRUD With Spring 3 + JPA + Hibernate 4 Entity Manager

A simple CRUD Application based on JPA.

This article will explain you step by step how to create simple CRUD application using ZK as Presentation layer with Spring 3 and JPA (Hibernate vendor).

What is JPA and why JPA
The Java Persistence API, referred as JPA is a object-relational mapping solution to enterprise Java applications.
JPA is a spec and not an implementation, so if you choose JPA, you still have to pick an implementation. You can pick Hibernate, Top link, and any other ORM that implements JPA.

Using JPA does not tie you to any particular ORM Like hibernate, toplink, etc. EntityManager provides vendor independent access to persistence. Portability across application servers and persistence products (avoids vendor lock-in).

Developers can choose the best ORM implementation according to the application requirement. For example, production can be started from the free versions of ORM implementation and when the needs arise it can be switched to the commercial version of the ORM framework. You can switch the persistence provides without changing the code. So, ORM framework independence is another another big benefit of JPA

Hibernate ORM
In this example, we are going to choose Hibernate as ORM vendor to build the simple CRUD Application.

Spring and Hibernate ORM Framework Integration.
There are lot of articles on the net about this topic. I recommend to the read following articles on this subject.


Technologies used in this example:

1. ZK 6.5.1 CE Version.
2. Hibernate-entitymanager 4.1.9 Final
3. Spring-orm 3.2.0 Release
4. Spring-web 3.2.0 Release
5. Java mysql connector 5.1.22

In mysql, create the following table

Part 1: First let us setup the development environment. Download this document and follow the step by step instruction to install the necessary software’s.

Part 2: This post explain how to create ZK Maven project in eclipse IDE as step by step.
Part 3: This post explain how to configure database, user name, password, etc using persistence.xml file
Part 4: This post explain how to integrate Spring and Hibernate.
Part 5: This post explain how to create DAO and service layer for the CRUD operation.
Part 6: This post explain how to create Presentation layer using ZK Framework.

Output before with ZK Default CSS Style



Output after defining our own CSS for each component.



Video demo:

You can download the source code here

MVVM Version of this tutorial is available here


  1. Excelent Work!, we use a similar Stack ejb3+zkoss over jboss 7.1. and inject the ejb3 with spring over zkoss. also use springsecurity with ACL.


  2. very nice sir ... I am a student and new to zk framework, the pdf you created is awesome helped me a lot.. thank you much much thank you... :) :)

  3. hi can you help me to understand why am getting this error message when i run the program pleae "CRUDExample.MyViewModel"

  4. Nice article for a new comer to learn Zk,Spring and Hibernate together

  5. Replies
    1. Thank you sudarshan. I am extremely happy for being great people like you visiting my blog and giving feedback.

  6. Hello and thank you for the Tutorials. Can you help me with an error? I tried following this example but got an error when started the app in Tomcat. I went back and downloaded your source file and get the same error.

    The Tomcat log can be found here:

    Can you help me identify what is wrong?

  7. Hi..nice work !

    I have te follow error:

    java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
    at org.zkoss.zkplus.spring.SpringUtil.getApplicationContext(
    at org.zkoss.zkplus.spring.SpringUtil.getBean(
    at crudexample.controller.UserListContrroller.doFillListbox(
    at crudexample.controller.UserListContrroller.onCreate$userList( ...

    Can you help me?


  8. Thank you for your article it’s looks good and providing some valuable information

  9. Thank you,so thank of this tutorial! Hope you have more the lession like this!AWS Training
    Thank agains!

  10. Hola buenas tardes.
    * Estoy trabajando con MVC tengo los iguientes archivos.
    * Vista1.zul
    * controlador
    public class Vista1_Controller extends SelectorComposer{
    * Vista2.zul
    public class Vista2_Controller extends SelectorComposer{
    en la vista 1 tengo un combo, panel, boton de guardar,
    el el evento del combo
    en el panel pinto una vista de la siguiente forma
    Executions.getCurrent().createComponents(zul, panelLE.getPanelchildren(), arguments);
    y hasta ahi no hay ningun problema,
    En el evento del boton de guardar tengo que llamar un metodo que esa en el cntrolador de la vista 2
    y lo estoy haciendo de la siguiente forma
    Vista2_Controller vista2_Controller = new Vista2_Controller();

    donde le metodo obtenerObjeto() me tiene que renornar un objeto que se llena con los
    datos que tiene la vista pero al hacer este llenado
    no encuentra los campos de la vista.
    y me muestra un error
    nullpointerexception null
    el error esta en esta linea al querer
    obtener el valor del campo
    catCarro.setNumeroLlanastas (txtbLlantas.getvalue());
    y el campo si tiene dato

    public CatCarro obtenerObjeto(){
    CatCarro catCarro = new CatCarro();
    catCarro.setNumeroLlanastas (txtbLlantas.getvalue());
    return catCarro();

  11. It fun to have a content like this really worth to read it
    AWS Training

  12. Error: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context:

  13. Please share me Source code for this application'the above link is not working

    mail me please

  14. Thank you for explaining JPA sir. I am developing web based application for one orthopedic hospital in Hyderabad, I follow your blog to stay good in my work.

  15. You have done very well its really helpful post for skinny head . if you are not satisfy to other .you can check this link and get your dental treatments. Orthopedic Hospital in Hyderabad

  16. Nice tips dear. Thanks for sharing it. I get lot's of beautiful tips clip in dental care Bariatric Surgery in Hyderabad

  17. Thanks for sharing. i really appreciate it that you shared with us such a informative post.. Orthopedic Surgeon in Hyderabad

  18. Thanks for sharing this we are for best travel company in jammu and kashmir we offer best and Jammu Kashmir Tour for family and couple book our best honeymoon tour for couple book and get best deals

  19. Curls & Curves is the Best Plastic Surgery Hospital In Bangalore Led by Dr Girish A C, who is known as Best Cosmetic Surgeon in Bangalore. He Offers Facial Cosmetic Surgeries, Hair Transplantation, Breast Surgeries and Much More.

    We offer Best Hair Transplant in Bangalore with Affordable Hair Transplant Cost By the Most Experienced Surgeons. Receiving a Hair Transplant can improve your appearance and self-confidence. We also focus on Breast Enhancement/Augmentation/ Lift/Reduction.
    Facial Contouring: Rhinoplasty, Chin, or Cheek Enhancement.
    Facial Rejuvenation: Facelift, Neck Lift.
    Body Contouring: Tummy Tuck, Liposuction, Gynecomastia Treatment.

  20. I definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work.

  21. i enjoyed a lot on your writing of this wonderful blog please keep more posts to understand more information and technology . cyber security online training india

  22. Dr. Jennifer Jose is recognised to offer the best Aesthetic Gynecology and Urogynecology procedures. You can visit our medical centers for more details about the procedures.

  23. Great information, Dr. Shailendra Patil is the well konwn and famous orthopedic surgeon in Kalyan. For more details you can visit on there portal or call on 8369026337


EDI 837 P Budget Number Example