-->
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.  [ 6 posts ] 
Author Message
 Post subject: StackOverflowError on flush()
PostPosted: Wed Mar 03, 2004 9:09 pm 
Beginner
Beginner

Joined: Wed Oct 01, 2003 3:47 pm
Posts: 44
Hello,

I'm receiving a StackOverflowError after updating 1 single object, and then calling flush() on the session (2.1.2). The default stack size is in place.

I'm flushing/closing the session in exactly the manner described in the docs under "manually managing JDBC transactions".

Unfortunately, this error has no stack trace whatsoever. I know it is occuring during flush due to my own debug statements before and after the call to flush().

For further investigation, I'd like to turn on a deeper hibernate log level, as I currently only get INFO messages from hibernate. But, under JDK1.4, I've tried:

Logger.getLogger("net.sf.hibernate.impl.SessionImpl").setLevel(Level.ALL);
Logger.getLogger("net.sf.hibernate").setLevel(Level.ALL);
Logger.getLogger("").setLevel(Level.ALL);

and none cause any other messages than INFO level from hibernate.

Does anyone have any idea on where to start looking? -- it's very frustrating not having a stack trace, and I'm not sure why that is. I know hibernate is doing some TRACE level messages during flush() that I'm not seeing in the error logs, and would like to for further pinpointing.

Thanks for your time,

Ryan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 9:25 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
1. use log4j
2. check equals/hashCode implementation. Overflow usually occurs on broken implementation.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Recursion due to flush->validation->flush cycle
PostPosted: Thu Mar 04, 2004 12:54 pm 
Beginner
Beginner

Joined: Wed Oct 01, 2003 3:47 pm
Posts: 44
Thank you, I'm using log4j and now have debug level output.

I've discovered the problem.

During flush(), hibernate is continuously processing the same dirty entity over and over again until a StackOverflowError occurs.

This occurs because a query within validate() of my entity queries the same object/table for any identical entries (a programmatic unique constraint).

Apparently, hibernate doesn't know which to do first. It goes to update the entity, performs validate, and then tries to run the query in validate. Since the query in validate is on the same table, hibernate thinks it needs to flush first. It tries to flush, runs the validate query again, flushes again, etc... Here's where the recursion comes in. Log output from one iteration of the recursive cycle is below.

To prevent this, perhaps hibernate should track when it is in a flush phase, and not allow another flush if already in a flush phase...

On a more practical note, are there any workarounds for this problem? We're trying to keep our entity validation as programmatic as possible.

Thanks,

Ryan


Code:
12:06:19,214 DEBUG SessionImpl:2210 - flushing session
12:06:19,215 DEBUG SessionImpl:2403 - Flushing entities and processing referenced collections
12:06:19,217 DEBUG AbstractEntityPersister:275 - com.thoughtatlas.blocks.Domain.name is dirty
12:06:19,218 DEBUG SessionImpl:2497 - Updating entity: [com.thoughtatlas.blocks.Domain#4fac08fd-fa602867-00fa-6028e0b5-0002]
12:06:19,219 DEBUG AbstractEntityPersister:275 - com.thoughtatlas.blocks.Domain.name is dirty
12:06:19,224 DEBUG AbstractEntityPersister:275 - com.thoughtatlas.blocks.Domain.modifyTime is dirty
12:06:19,234 DEBUG SessionImpl:1556 - iterate: SELECT COUNT(object) FROM com.thoughtatlas.blocks.Domain AS object WHERE object.name = :value AND object.id <> :id
12:06:19,235 DEBUG QueryParameters:108 - named parameters: {value=bob.com, id=4fac08fd-fa602867-00fa-6028e0b5-0002}
12:06:19,242 DEBUG QueryTranslator:147 - compiling query
12:06:19,252 DEBUG SessionImpl:2210 - flushing session

....etc....

until a StackOverflowError


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 3:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Do not access the session from validate(). The session is in a fragile state during the flush process.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 10:34 pm 
Beginner
Beginner

Joined: Wed Oct 01, 2003 3:47 pm
Posts: 44
Fair enough. :)

As a work around, what if I set the flush mode to NEVER during validate(), and then back to AUTO at the end of validate()? Still dangerous?

Best regards,

Ryan


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 1:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
yes, still dangerous. Note that you are allowed to open a new session on the same connection and execute queries on that session.


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