0

how to declare @Transactional method in ViewModel

asked 2013-01-29 03:18:56 +0800

yaminglin1977 gravatar image yaminglin1977
36 2

i try zk+spring+hibernate,i want to declare transactional method in VM, so the following code is written:

  @Component
 public class SomeViewModel {
   @Command
   public void cmd() {
       save();
   }
   @Transactional
   public void save(){
         ใ€‚ใ€‚ใ€‚//database operation
   }
 }

when it run ,it throw following exception :

org.zkoss.zk.ui.UiException: cannot find any method that is annotated for the command cmd with 

      @Command in org.lym.exam1.ctrl.SomeViewModel@1f1df3f
      at org.zkoss.bind.impl.BinderImpl.doExecute(BinderImpl.java:1511)

please tell me how to realize the function of this?

delete flag offensive retag edit

Comments

I will suggest you to wrap Transactional in service or dao bean, and them could be a spring bean

dennis ( 2013-01-29 06:43:38 +0800 )edit

4 Answers

Sort by ยป oldest newest most voted
0

answered 2013-01-29 03:56:31 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Warning: Register a Composer (or ViewModel) as a Spring bean Many developers tend to register ZK's composer (or ViewModel) as a Spring-managed bean, but we do not recommend this approach because none of Spring's scopes matches correctly with the life cycle of the composers, please see ZK Developer's Reference/MVC/Controller/Wire Variables for more details. The scope of a composer is "desktop" scope that is shorter than "session" and longer than "prototype". Only ZK knows when to create composers (or ViewModel), so it's better to let composers be managed by ZK

You can read this link

And also, in my blog, there is an example on this subject. here is the link

link publish delete flag offensive edit
0

answered 2013-01-29 08:03:40 +0800

nabil87 gravatar image nabil87
28 1 2

updated 2013-01-29 08:10:03 +0800

Why do you want your vm to be a component?

If it is just for the @Transactional just delete @Component you don't need it.

If you want to access a method of your vm inside another calss use http://www.zkoss.org/javadoc/latest/zk/org/zkoss/bind/BindUtils.html (BindUtils.postGlobalCommand)

btw: A good http://www.ibm.com/developerworks/java/library/j-ts1/index.html (article) about transaction patterns

link publish delete flag offensive edit

Comments

spring do the transaction aop ,so i set VM a component,there is nothing with binding,i cant get you

yaminglin1977 ( 2013-02-01 23:39:08 +0800 )edit
0

answered 2013-02-01 07:46:20 +0800

yaminglin1977 gravatar image yaminglin1977
36 2

updated 2013-02-01 08:02:07 +0800

thank all,

the reason why i declare @transactional in VM is to avoid using 'open session in view' pattern which is is discussed in

http://stackoverflow.com/questions/1103363/why-is-hibernate-open-session-in-view-considered-a-bad-practice

, So if i invoke multiply service methods in a VM method without OSIV,I can't guantee these service methods is in single transaction. how to implement this goal without using 'open session in view' pattern?

link publish delete flag offensive edit
0

answered 2013-02-01 08:11:49 +0800

yaminglin1977 gravatar image yaminglin1977
36 2

updated 2013-02-01 08:24:15 +0800

I thought of two solution for my own question:

No 1: this multiply servcie methods are reconstructed into single service method,the disavantage is that service layer is influnced by present layer.

No 2: using Vistor Design Pattern to let service method visit VM's member,so i can declare transaction annotation on service method ,meanwhile declaring binding annotation on VM's method.

About this question, I very want to hear other people's advice besides the front advice .

link publish delete flag offensive edit
Your answer
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

Follow
2 followers

RSS

Stats

Asked: 2013-01-29 03:18:56 +0800

Seen: 95 times

Last updated: Feb 01 '13

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