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.  [ 4 posts ] 
Author Message
 Post subject: ScrollableResults: problem with dirty check
PostPosted: Wed Sep 13, 2006 12:51 pm 
Newbie

Joined: Wed Sep 13, 2006 12:30 pm
Posts: 6
[version 3.1.3, oracle 9.2.x]

i have a problem with ->
http://www.hibernate.org/hib_docs/v3/re ... tch-update

after the session gets cleared (session.clear()) hibernate does not detect an update(dirty detection) of the model on the next entity from ScrollableResults; this just happens on the FIRST entity after clear, dirty checks are ok on further entities

-> 2 many-to-one relationships are changed for each entity in the loop

if i remove the session.clear() everything works fine;
WITH session.clear() the update statement for these 2 many-to-one changes are not flushed by hibernate

any ideas?

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 10:37 am 
Newbie

Joined: Wed Sep 13, 2006 12:30 pm
Posts: 6
the problem is that a ScrollableResults.next() already loads the object into the session and not ScrollableResults.get();

so this, for instance, does not work (in my case):

public class ScrollableResultSetWrapper implements Enumeration {

private ScrollableResults results;
private boolean more = false;
private boolean closed = true;

public ScrollableResultSetWrapper(ScrollableResults results) {
this.results = results;
this.more = results.next(); // init
this.closed = false;
}

public boolean hasMoreElements() {
return this.more;
}

public Object nextElement() {
if (!hasMoreElements())
throw new NoSuchElementException("No more entries");
else {
Object current = results.get();
this.more = results.next();
return current;
}
}

}

... because you can't clear the session with the next element already in there...

have to do a little rework...


Top
 Profile  
 
 Post subject: Re: ScrollableResults: problem with dirty check
PostPosted: Tue Sep 26, 2006 2:27 am 
Newbie

Joined: Mon Sep 25, 2006 7:42 am
Posts: 7
try giving session.flush(); in between or after the update statments
This will refresh the session with the Database and will detect the updates in the same transaction.,



-- Do response with giving credits if it works....
starzer wrote:
[version 3.1.3, oracle 9.2.x]

i have a problem with ->
http://www.hibernate.org/hib_docs/v3/re ... tch-update

after the session gets cleared (session.clear()) hibernate does not detect an update(dirty detection) of the model on the next entity from ScrollableResults; this just happens on the FIRST entity after clear, dirty checks are ok on further entities

-> 2 many-to-one relationships are changed for each entity in the loop

if i remove the session.clear() everything works fine;
WITH session.clear() the update statement for these 2 many-to-one changes are not flushed by hibernate

any ideas?

thanks

_________________
Never Give Up


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 26, 2006 3:13 am 
Newbie

Joined: Wed Sep 13, 2006 12:30 pm
Posts: 6
...switched to (so there is no need to flush in the loop each time):

public class ScrollableResultSetWrapper implements Enumeration {

private ScrollableResults results;
private Object current;
private boolean closed = true;
private boolean more = false;

public ScrollableResultSetWrapper(ScrollableResults results) {
this.results = results;
this.closed = false;
}

public boolean hasMoreElements() {
more = results.next();
if (!more) {
close();
return false;
}
current = results.get();
return more;
}

public Object nextElement() {
if (!more) {
throw new NoSuchElementException("No more entries");
}
return current;
}

public void close() {
if (!closed) {
results.close();
}
closed = true;
}

}

this works with the code in
http://www.hibernate.org/hib_docs/v3/re ... tch-update


thanks


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