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: Possible race condition or cacheing issue in Hibernate?
PostPosted: Fri Sep 24, 2004 6:53 pm 
Newbie

Joined: Mon Sep 13, 2004 2:23 pm
Posts: 6
Location: Los Angeles
Hibernate version: 2

One of my tests creates an object, stores it to the database with Hibernate and then attempts to retrieve it 100 times in a for loop:

dao = DataAccessLayer.getInstance(); // call to Spring context to return a Singleton
MyPojo newPojo = createNewPojo();
MyPojo pojo = null;
dao.saveMyPojo(newPojo); // regular Hibernate call, which stores it to Oracle
int j = 0;
while( pojo== null && j < 100 ) {
pojo = dao.getMyPojo(newPojo.getID());
log.info("Retrieval attempt " + j);
j++;
}
assertNotNull("This should not be null after this call!! Failed on index:" + i, pojo);


Problem is that this test fails intermittently. The object gets stored without an error being generated but the loop is sometimes unable to retrieve it after a random amount of attempts (might be #2 or #67, #24, etc.). I also have a reverse scenario where the instance was deleted and should be null when asserting. Similarly, sometimes the object suddenly exists after an intermittent number of retrieval attempts.

What could cause these types of problems? I do have my DataAccessLayer object act as the session manager, btw (if anyone is interested I can share my configuration file).

Any input/pointers on this problem would be greatly appreciated, this is really putting me in a bind.

Michael

_________________
The problems that exist in the world today cannot be solved by the level of thinking that created them -- Albert Einstein (some smart dude)


Top
 Profile  
 
 Post subject: Entire code:
PostPosted: Fri Sep 24, 2004 7:35 pm 
Newbie

Joined: Mon Sep 13, 2004 2:23 pm
Posts: 6
Location: Los Angeles
Looks like I forgot some pieces of this test, without which it doesn't make sense. Here's the complete and real test (different object name):

public void testRemoveNavigationNodeForLoop() throws Exception {
for( int i=0; i <100; i++) {
INavigationNode newNavNode = createNewNavigationNode();
dao.saveNavigationNode(newNavNode);
INavigationNode navNode = null;
int j = 0;
String id = newNavNode.getID();
while( navNode == null && j < 100 ) {
navNode = dao.getNavigationNode(id);
log.info("Retrieval attempt of stored navigationNode " + j);
j++;
}
assertNotNull("The navigation node should not be null after this call!! Failed on index:" + i, navNode);

dao.removeNavigationNode(newNavNode);
int k = 0;
while( navNode != null && k < 100 ) {
navNode = dao.getNavigationNode(id);
log.debug("Retrieval attempt of deleted navigationNode" + k);
if (null != navNode) {
log.debug("WARNING: was able to get navigationNode with ID: " + id);
}
k++;
}
assertNull("The navigation node should be null after this call!! Failed on index:" + i, navNode);
log.debug("********************************");
}
}


This really looks like a Spring/Hibernate transaction problem to me.

_________________
The problems that exist in the world today cannot be solved by the level of thinking that created them -- Albert Einstein (some smart dude)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 24, 2004 8:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Use your debugger and the Hibernate log to find the bug in your code. Make sure you understand correct Hibernate session scopes and are doing correct transaction handling.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 24, 2004 9:38 pm 
Newbie

Joined: Mon Sep 13, 2004 2:23 pm
Posts: 6
Location: Los Angeles
gavin wrote:
Use your debugger and the Hibernate log to find the bug in your code. Make sure you understand correct Hibernate session scopes and are doing correct transaction handling.


I'm using Spring for Hibernate session handling. My DataAccessLayer is defined as the session manager for all transactions - everything is defined very much like it's done in appfuse. I really don't see anything wrong with my code and I find it pretty interesting that you immediately assume that there's a bug in my code.

I'm not here for some out-of-the-box toss downs - how about providing some real input, otherwise don't bother replying.

_________________
The problems that exist in the world today cannot be solved by the level of thinking that created them -- Albert Einstein (some smart dude)


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.