-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Q: SessionPerRequest with JSF navigation
PostPosted: Wed Dec 07, 2005 12:47 am 
Beginner
Beginner

Joined: Wed Oct 05, 2005 12:29 pm
Posts: 22
Hi,

I have been pondering about this particular issue regarding the usage of SessionPerRequest with JSF. In the SessionPerRequest pattern, a hibernate session is open and a transaction started at the beginning of the request, and the transaction is committed just before returning a response to the browse.

I have been using this pattern for a while until a couple days ago I realized that a request in JSF usually involves an action that navigates to another JSF. For example a viewCustomer.jsf could have a delete customer button, which deletes the customer and navigates to listCustomer.jsf. The sequence of action is thus:

1. Begin hibernate transaction
2 .deleteCustomerAction()
3. Deletes customer from database
4. JSF navigation to listCustomer.jsf
5. Retrieve and display customer list
6. Commit hibernate transaction

There are two distinctly independent operations within the same Httprequest. To be correct – the transaction should commit after step 3, and a new transaction should begin. If I use ‘redirect’ in JSF navigation that is what it would amount to. But what is the proper way to inject the commit without redirect?

Regards,
Yee


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 2:32 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
redirection is transparent to the ORM. the request is either forwarded or redirected based upon how you have configured faces-config.xml .

Try to commit the transaction in the 'Invoke Application' phase, not the filter. This is the phase in which your action is invoked. This way you can declaratively forward/redirect the request based upon the OUTCOME of the transaction (pretty error page or retry unit of work).

Also remember the 'render response' phase is going to be next. If you have really long value bindings, like #{custumer.order.item['foo'].name}, hibernate will do a lot of lazy loading. Put something like this in the use case you describe, 'display customer list', and you have a lot of trips to the database. So ... try to load as much as you can PRIOR to the rr phase.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 1:58 am 
Beginner
Beginner

Joined: Wed Oct 05, 2005 12:29 pm
Posts: 22
Thanks Dennis.

That makes sense. Would that be classified as a hibernate pattern for JSF?

Actually I have been doing this without any noticable ill effects. Hibernate auto flushing seems to handle the situation quite well. I have also been wondering whether it makes any difference ultimately.

I find lazy loading very thorny to work with ... still pondering about this.

Regards.
Yee


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 2:03 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
yeecn wrote:
Would that be classified as a hibernate pattern for JSF?


maybe it's a JSF pattern for hibernate ;)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 2:16 am 
Beginner
Beginner

Joined: Wed Oct 05, 2005 12:29 pm
Posts: 22
yeecn wrote:
Actually I have been doing this without any noticable ill effects.


Sorry - what I meant to say is that I have been blissfully ignorant of this issue as yet I did not notice any ill effects.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.