-->
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.  [ 2 posts ] 
Author Message
 Post subject: scrolling through a list
PostPosted: Fri May 21, 2004 12:09 pm 
Beginner
Beginner

Joined: Mon Dec 15, 2003 11:34 am
Posts: 22
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();


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 21, 2004 2:41 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
So to make sure i understand what your asking. You essentially want read-repeatable transaction isolation during both of those sessions. Correct?

There would be a couple of ways to acheive this. The first would be to utilize the transaction isolation of you underlying database. Of course that would mean needing to keep open the Hibernate session and the transaction during the entire time a user is playing with this paging list. The isolation would need to be set at READ_REPEATABLE or higher, which tends to get very expensive. You might be able to do something here with isolation set to SERIALIZABLE and utilizing serialazable transactions and disconnected sessions.

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.


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