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