Using MVVM, how can I delay bean setters calls?

asked 2015-08-18 07:20:06 +0800

MathieuPiette gravatar image MathieuPiette
1567 3


I have a problem for using Hibernate with ZK and the MVVM approach.

I have a page that is quite complex (not really complex but a lot more than the examples) and is backed up by an only ViewModel.

In this page, I have a ListBox whose model is bound to a private List<MyObject> mainList in the ViewModel. The selected item of that ListBox is bound to private MyObject selectedMyObject in the ViewModel. Every MyObject bean has a field that is a List<MySubObject>, so in the *.zul, I have an other ListBox whose model is bound to selectedMyObject.mySubObjects.

On the GUI side, everything seems to be working fine, every component is bound correctly, the GUI refreshes correctly when it needs to, etc. But on the server side, I have a problem.

What I am trying to acheive is this: I do all the modifications in the GUI, then I hit a "save" button, and everything is saved to the database (the "save to database" operation is already written and works).

My problem is that some changes are saved to the database even when I didn't click on the save button.

Due to the lazy initialization process of Hibernate, some collections are retreived from the database quite late, after I already made some changes in the GUI. In that case, it may happen that Hibernate flushes to the database the changes I made before retrieving the missing collection. This is to ensure that the SELECT that Hibernate does retreives a coherent set of data.

So, what I'd like to do is have a kind of cache to avoid calling the setters directly on the Hibernate managed beans. Is there a way of doing it with ZK?

I heard of the "Middle object" system, but could not find documentation about advanced usage. It seems to be efficient when we have a form backed up by only a bean. But in my case, I have a list of beans, then another bean that is actually one of these, each of the beans of the list also has a reference to a list of other bean, etc.

How can I solve my problem?

Many thanks in advance for any useful information!

delete flag offensive retag edit


search the form object for the middle object, in ZK8 they can handle lists also good.

chillworld ( 2015-08-18 08:42:18 +0800 )edit

Thank you @chillworld, I'll try ZK 8. Do you have a link to a comprehensive documentation for Middle Objects? I could only find small talks and introductions.

MathieuPiette ( 2015-08-18 09:32:16 +0800 )edit

Well I tried to used ZK 8 but I've come accross a vicious bug: ZK transforms my ViewModel properties to proxies, but those properties are already Hibernate proxies. So they are proxies of proxies. Both ZK and Hibernate use Javassist to "proxify" a class so I get a duplicate method exception.

MathieuPiette ( 2015-08-21 11:59:22 +0800 )edit

The duplicated method is "void setHandler(MethodHandler mi);" in javassist.util.proxy.Proxy

MathieuPiette ( 2015-08-21 12:00:47 +0800 )edit
Be the first one to answer this question!
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

1 follower



Asked: 2015-08-18 07:20:06 +0800

Seen: 12 times

Last updated: Aug 18 '15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More