0

I really need an answer : Could we / Should we manage our hibernate Transaction in ZK

asked 2009-03-06 15:10:23 +0800

bob007 gravatar image bob007
384 3 4

updated 2009-03-16 14:48:07 +0800

*** ANSWERED/SOLVED ***

Hi all,

In Smalltalk Hibernate + ZK its write:

Notice that to demostrate the cross thread capability of the new ZK listener,
 we don't start the Hibernate session nor commit the data in EventDAO.
 We will use the so called "OpenSessionInView" pattern instead.
 For each Execution, a Hibernate Session would be automatically opened at the begin and closed at the end.

I understand it like that : we don't have to manage the Sessions/Transactions. But it don't specify if we could do it.

I really need an answer :
Could we / Should we manage our Hibernate Transactions ???
If we shouldn’t manage our Transactions, why ?
What this may cause ? Problem with threads ?




Ok I explain the situation :

I had a problem with a class with a many-to-one relation not committing : here

I solve my problem by managing myself my Transactions (begin/commit) , but I got an exception (here)
from ZK invokeExecutionCleanups and ZK OpenSessionInViewListener.
This exception is only show in console and don't seem to disrupt my application.


So now before I undo all my Transactions in all my DAO, or continue in this way,
I really need to be sure if I can or should use Hibernate Transactions (begin, commit). And else why ?


Thanks for answers,
Steve

delete flag offensive retag edit

16 Replies

Sort by » oldest newest

answered 2009-03-06 15:35:28 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-03-06 15:41:38 +0800

Hi Steve,

i use zk with spring + hibernate in the backend. At time against a PostgreSQL.

The backend is a separate Eclipse project and have nothing todo with zk.
So at time i don't know what your problem is. I mean you should not mix
you database layer with zkoss.
-----------------------------------------------------------------

We have a helperclass and additionally all the transaction stuff is done by
spring by a aop configuration. So i have nothing more todo with the transaction.

It's to big to posted all here. So send me your email address at sge(at)forsthaus(dot)de.
I will send you my backend test package. So you can look at the code yourself. Please write
here for the others if you found a solution .

Whises
Stephan

PS: help to prevent the global warming by writing cool software.

link publish delete flag offensive edit

answered 2009-03-06 15:53:07 +0800

bob007 gravatar image bob007
384 3 4

updated 2009-03-06 15:54:59 +0800

Hi stephan,

Thanks for your answer.
Unfortunately I don't know Spring and I don't have the time to integrate it for this project. But for the next project I will probably use Spring.
But for now i will continue with Hibernate without Spring (no choice :-( )

regards
Steve

link publish delete flag offensive edit

answered 2009-03-06 16:00:10 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

OK Steve,

i don't use a special zkClass for hibernate. So i have no idea what goes wrong.

Can you explain with some code how is the workflow for a typically access in your webApp.

Stephan

link publish delete flag offensive edit

answered 2009-03-06 16:29:24 +0800

bob007 gravatar image bob007
384 3 4

updated 2009-03-06 16:31:59 +0800

Stephan,

I don't use a special zkClass neither. I use some java class DAO (like here)

Steve

link publish delete flag offensive edit

answered 2009-03-06 19:41:43 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-03-06 20:00:11 +0800

hmmm Steve,

your code

public class HeuresEffectueesRowRenderer implements RowRenderer {
            public void render ( Row row, Object data ){
               //if i access repondant then i can't save-update a new HeuresEffectuees.
               new Label(((HeuresEffectuees)data).getRepondant().getNom()).setParent(row);
               new Label(((HeuresEffectuees)data).getNbHeuresEffectuees().toString()).setParent(row);               
               new Label("").setParent(row);
            }
         }

It's exactly what i have written above what happens to the structure of your relation!
Let have a look on this thread. Ups, i see this was an other user. But okay let's go on.

      new Label(((HeuresEffectuees)data).getRepondant().getNom()).setParent(row);
      
      HeuresEffectuees (bean/getter/setter)
         private long id
         private string dummy
         private Set Repondant
         ...

                Repondant (bean/getter/setter)
                   private long id
                   private String nom
                   ...

I cannot see what your input is, when you are storing the objects. Please do a log/SysOut from the objects before storing. If you are shure that the second (related Repondant) object is in the database when you save the mainly object() HeuresEffectuees?

OK, what i mean is i have at no time try out what happens when you want to saveAndUpdate() a new Object with a new Object in relation. I.e. new HeuresEffectuees() and new Repondant() at the same time.
In my logic it must be sure that the second (related) object is already in DB or if not, it must be safed before the main object.
You can see this if you fill a Database with several related tables with a demo-data-script.

Apart from this, you must at every time use the tx.commit/tx.rollback.


i'm longing to know if both (main Object and relation object are new to the database).

Stephan

PS: no event have control over my CRUD data. And that's good.

link publish delete flag offensive edit

answered 2009-03-06 20:33:04 +0800

bob007 gravatar image bob007
384 3 4

updated 2009-03-06 21:08:19 +0800

@Stephan,

thanks for answer,

I don't think its a problem of contain since its committing well when i manage myself my transaction.
Yes, I did a SysOut before storing and the data is OK. Yes, i'm sure the Repondant is in the database since I take it from a loaded list.

No only the main object is new to the database and I don't insert/update the related one in same time since I use insert="false" update="false" in my many-to-one relation.

Are you totally sure I can use transaction begin/commit without problem ?
I wanted as many confirmation as possible because only two people answered me : one said Yes and the other said No.

I mean this is working, but I'm still worried about the hidden ZK invokeExecutionCleanups and ZK OpenSessionInViewListener Exception

I was wondering if I do it with transaction begin/commit :
Since the problem for org.zkoss.zkplus.hibernate.OpenSessionInViewListener.cleanup
is "Transaction not successfully started" maybe i put a sess.beginTransaction(); just after my commits maybe it will solve the problem ?
Can it work ?

thanks,
Steve

link publish delete flag offensive edit

answered 2009-03-07 00:44:22 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-03-07 01:04:46 +0800

Hi Steve,

Firstly, equal what others said. It's an absolutly MUST DO to wrap all database access to a transaction.

It's the old banking sample. Take 100$ from one account and book it to an other account and unplugg the power of the booking machine (computer) in the middle of the transaction process!! On your account there is -100$ and your friend have nothing added on his account. Where are the other 100$ ?????

Therefore we need a transaction. ALL is done correct or nothing should be. It means ALL what is booking till now is ROLLEDBACK when their was a failure.

So it's better to do it for all. So you burn it in you brain. :-)

  try
    save/delete
    commit
  catch
    e
    rollback
  -

You said you have no zk-Hibernate stuff calls.

From what came org.zkoss.zkplus.hibernate.OpenSessionInViewListener.cleanup ???
So i don't know if you work with some special classes for zk. In my case i have nothing special. My backend hibernate stuff is/must absolutly free from zkoss et vice versa. It's a seperate layer !!!!

Because i'm pull Lists<Customer> or objects Customer. Or i send it back saveOrUpdate/delete(customer).

I mean you have somewhere refering some special zkClasses (org.zkoss.zkplus.hibernate.OpenSessionInViewListener).
Have a look in you web/zk.xml's

For what you need these classes?

As i said before, i don't know what you are will doing in your code and what is your workflow for this and what you have imported for this.
When you call direct a DAO methode where comes the zkoss stuff in the errormessage ???????

Comes these messages from working with some binding classes?
I have no Binding Features!!! For what!! I'm absolutly against the zscript stuff in a zuml-file. It forces to mix View and Logic with this feature. There is no change for a nearly MCV pattern. ZK is a absolutly great framework!! You have with it the chance to do all what you need in one language. Java!!

Steve, have a look over your project. Kill step by step all what you don't know for what it is.

All will be good :-) :-)

whishes
Stephan

PS 1: Try to delete the update=NO Insert=no tags in your mapping file. For what is that???
As i understand you. You do it very correct self in your DAO methodes.
PS 2: Have a look. Is there standing autocommit=yes ?

link publish delete flag offensive edit

answered 2009-03-07 21:41:34 +0800

bob007 gravatar image bob007
384 3 4

updated 2009-03-07 22:28:39 +0800

Hi Stephan,

Thanks for your answer,

No I don’t use directly org.zkoss.zkplus.hibernate.OpenSessionInViewListener.
I did as in the ZK The Developer's Guide and add some lines in zk.xml for Hibernate.

...
<!-- Hibernate OpenSessionInView Pattern -- >
<listener>
<description>Hibernate Open Session In View life-cycle</description>
<listener-class>org.zkoss.zkplus.hibernate.OpenSessionInViewListener</listener-class>
</listener>
...


Regards,
Steve

link publish delete flag offensive edit

answered 2009-03-07 23:29:37 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-03-07 23:31:20 +0800

Hi Steve,

OK. It seems that this is a helper class for something.

I take a short look in it. I hope you does it too.

Yes, this class handles the transaction/commit/rollback for you.
So you don't need tx.begin/commit/rollback in your code when you use this class.

Stephan

link publish delete flag offensive edit

answered 2009-03-08 00:02:08 +0800

bob007 gravatar image bob007
384 3 4

Hi Stephan,

Thanks for your answer,

Yes we don't have to manage Transactions begin/commit/rollback, since the OpenSessionInViewListener do it
But could we do it ?
Because if we couldnt, we have no control on the transactions...

Regards,
Steve

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

RSS

Stats

Asked: 2009-03-06 15:10:23 +0800

Seen: 461 times

Last updated: Mar 10 '09

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