# how to integrate zk framework with spring & hibernate, it's possible ?

progamerdotcom
117 5

Good morning all,

I want to integrate zk to other framework such as spring and hibernate.

Are you ever to do it ? , if you do, please point me some tutorial about these integration.

Thank a lot.

Regard,

Pro G.

delete retag edit

## 12 Replies

blacksensei
234 2

Yes it's possible with ZK 5.0.x . I use hibernate annotation with either with entityManager or session. I use spring to have cute url eg. http://localhost:8080/zktest/index instead of http://localhost:8080/zktest/index.zul . so there is no Spring MVC controller, i still use ZK MVC Controller which is actually wired by spring with the prototype scope. on the mapping to the view i use <mvc:view-controller in spring applicationcontext.

Now with the ZK 6 it seems not to be working. i posted on this forum but it seems it hasn't interested anybody yet :(

MontyPan
435 3
http://xitop.blogspot.com...

Hi progamerdotcom,

Integrate Hibernate to ZK works fine.
The goals of these two framework is different, use Hibernate to operate database, use ZK to handle user action and present data,
they are independent.

There is another reference about Use CDI in ZK:
http://books.zkoss.org/wiki/Small_Talks/2012/September/Practices_Of_Using_CDI_In_ZK

Regards,
Monty Pan

progamerdotcom
117 5

:)

aros54
66

In my experience there is no problem to integrate ZK, Spring and Hibernate as well as many other tools and frameworks available in the J2EE world. However, as there are some overlapped areas, the key of success is to choose the rigth tool to perform the thing it does better and, of course, be careful on choosing the compatible software versions.
Hibernate is an ORM tool, very good to free your application code from the DBMS used. ZK is typically used to manage the view part of the application, although it can be helpful on writing the controller functionalities too. Spring framework does a lot of things. A feature that cannot be renounced is the IoC container. Also Spring security module is a good choice.
Everyone of these tools do much more than what I said. It is important that you carve out your way to use each tool for every specific usage and how they couple together. For instance, Spring has a native integration with the data access made through Hibernate while ZK provides an integration library with Spring, etc.
I have a pretty long experience of projects made using this technology. If you have any particular question about it or need help on specific architectural problems feel free to contact me directly at this mailbox whoa4999 AT gmail DOT com.

progamerdotcom
117 5

I already begin zk with hibernate and spring integration, it's OK,

but I have some problems, how to inject a DAO from other DAO,

for example I have patientDaoImpl that must inject doctorDao,


public void saveTreatment(Patient patien){
//Here I want to inject doctorDao
}


Thanks for sharing

9393 3 7 16
http://www.oxitec.de/

have a look at the codes and configuration files from the Zksample2 backend sub project.

best
Stephan

aros54
66

If you google around you can find a lot of code sample about Dao injection. Zksample2 is a good place. I would add that object injection is Spring's know-how. So look at Spring code samples to understand this matter.
Anyway, just to say one word about your question, in my opinion you shouldn't inject a Dao with another Dao. A Dao object is a Data Access Object, specialized to access one and only one data object. You have one Dao for Patient entity and another Dao for Doctor entity as well as their daoImpl actual implementation. What you are trying to do - that is the union of several Daos to perform a complex data access - should be done using a Service interface. The method saveTreatment is a method of HospitalService interface, whose HospitaleServiceImpl actual implementation can be injected with patientDao, doctorDao, nurseDao, medicineDao, etc.
Spring bibliografy is full of these expamples.

progamerdotcom
117 5

Thank Stephan and Adriano,, zksample with new documentation, last update Oct 05, 2012

double thanks masters

9393 3 7 16
http://www.oxitec.de/

:-) Yeah, i have update a little bit about spring scopes. I have had a problem for getting a controller.
After a few tries i remember for the ultimate weapon. the EventQueue as a global listener helped me to call methods from everywhere in the application.

best
Stephan

progamerdotcom
117 5

yes Sir :-) ,, I am new in ZK, I will learn Zksample2,, I already checkout zksample2 in my eclipse but its in one project, I confused how to run it, 4 projects in a zksample2 project bundle and I read your documentation, try to run zksample, http;//localhost:8080/ ,, wheres the path to access main index zksample2, ( zkoss project as frontend).

Thanks Sir.

[hide preview]