-->
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.  [ 14 posts ] 
Author Message
 Post subject: Application with multiple list
PostPosted: Thu Aug 26, 2004 8:34 pm 
Beginner
Beginner

Joined: Mon Dec 15, 2003 11:34 am
Posts: 22
I have applications that allow users to page through multiple tables using a web front end and access to these tables is through stateless EJB's. I am assuming I need to use ScrollableResults and I need to keep the Session open when going back and forth to the web tier.
When I want a new page from a previously displayed list, how does Hibernate know what cursor to use ? Do I need to keep a different Session for each Query ?

thanks,
Adam


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 26, 2004 8:48 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Use setMaxResults()/setFirstResult().

I wrote a recent blog entry on this, so check that out.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 4:58 am 
Beginner
Beginner

Joined: Mon Dec 15, 2003 11:34 am
Posts: 22
Thanks. Where can I find this blog ?

thanks again


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 5:03 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
http://blog.hibernate.org/cgi-bin/blosx ... ation.html

you should always check the blog; there are a lot of great docs and article to learn.

Hibernate comes with many many free docs ;))

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 5:30 am 
Beginner
Beginner

Joined: Mon Dec 15, 2003 11:34 am
Posts: 22
Quote:
Another option would be to utilize the Hibernate scroll() approach. The list() method you are currently using is roughly equivalent to the jdbc ResultSet. What you want instead is an equivalent to jdbc's ScrollableResultSet. In Hibernate, that would be the ScrollableResults obtained through the scroll() method. Here, too, you would still need to do some work to make sure the session remains available while scrolling.



Thanks again. I had looked at that blog earlier, but was still concered about implementing paging that way, because we have multple user who use the system and updates that occur simultaneously by different applications.

For example, what if I have rendered a view ( for user A ) and another user deletes items ( in another session ) but from the same list of items. Using that pagination exampled in that blog, user A will skip an item if another user in another session deletes an item from a similiar list.

This is why I am trying keeping the session open and using a ScrollableResult .This was the approach 'Steve' had recommended to me in a post while back.

I am wondering though that if I use this approach, how to associate the ScrollableResults ( which I assume represents the cursor ) with the various list I am displaying within the application and are being manipulated in the application.
If I use the same session for all the queries, will Hibnernate be able to find the proper open cursor when I subsequently do a scroll on a particular list ?
How will Hibernate know which cursor to use ?

thanks again,
Adam


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 5:39 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Quote:
Using that pagination exampled in that blog, user A will skip an item if another user in another session deletes an item from a similiar list.


Which is, in almost all cases, the expected and correct behavior from the POV of the user.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 5:55 am 
Beginner
Beginner

Joined: Mon Dec 15, 2003 11:34 am
Posts: 22
Not really.

This was my original post

Quote:
Hi,
What I am trying to do seems pretty simple and a straightforward implementation of the setMaxResults and setFirstResult API's.
Below is the code I am using to retrieve a list. Once the list is retrieved I am creating a subset of the list to return to the user and I am using the setMaxResults & setFirstResult API. This works fine in a single user siduation and there is no problem scrolling through the list using this code. However, the probelm arises when I have 2 sessions going against an identical list using this code.
If one session ( user ) deletes an item from the list, the first user skips records that should be there when scrolling. If no deletion ( or insertion ) occurs then scrolling through the list works fine.

Can anyone recommend a workaround or a more suitable way of coding

Criteria crit = session.createCriteria(fromData.getClass()).add( Expression.between(readKey, fromReadValue, toReadValue));

crit.setMaxResults(5);
crit.setFirstResult( ( 5 * get_cur_page_number() ) );

list = crit.list();


that's why I'm trying this alternate technique with the ScrollableResults and the open Session.

But my questions from above remain ?

thanks again,
Adam


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 6:01 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
A new Session will get a new JDBC connection, the old connection will be closed and the cursor is gone. There is no good way to do what you are trying to do.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 7:10 am 
Beginner
Beginner

Joined: Mon Dec 15, 2003 11:34 am
Posts: 22
Hi,
So for clarification.
There is no good way to a have a web application that displays multiple lists from stateless EJB's to scroll through multiple list of items from a large database ?

What is the issue ? Trying to scroll through different lists ? Or trying to keep the cursor open to efficently scroll through these list ? Or tying to associate different lists with a session ? Would having a session per list work ?



thanks,
Adam


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 7:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
The issue is that web applications are not allowed to keep a transaction (or cursor) open across a user interaction. This is not really a hibernate-specific things. It is common to all server-side Java code.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 9:22 am 
Beginner
Beginner

Joined: Mon Dec 15, 2003 11:34 am
Posts: 22
I thought the abiltiy to keep a transaction ( and I was assuming a cursor ) open across multiple Request/Response cycles was what has been referred to as "long transaction" and has been discussed as the the session-per-application-transation, which in your ( Gavin ) blog is the proper way of handling a session object when this is required

I was trying to do this with the session.disconnect and session.reconnect. Am I not going to be able to keep a database transaction open across multiple Request/Respone requests as well?

this patter is discussed in the article
http://www.hibernate.org/168.htm

What is the difference between what this article talks about in terms of a long database transaction and keeping a cursor open ? Can I do one, but not the other ?

thanks,
Adam


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 9:30 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
A long running application transaction involves several JDBC database transactions. It's not a long running database transaction.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 9:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You could keep the session open - that is however an antipattern IMHO


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 31, 2004 3:43 pm 
Beginner
Beginner

Joined: Mon Dec 15, 2003 11:34 am
Posts: 22
OK. Please do not take this as a criticism as I like working with Hibernate very much, but given the way session beans work, doesn't that make using setMaxResults()/setFirstResult() not very useful ( at least in this circumstance ). I only ask to make sure I understand the issue

thanks again,
Adam


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 14 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.