-->
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: Bug in AbstractEntityPersister causes silent exceptions
PostPosted: Thu Mar 15, 2007 3:10 pm 
Newbie

Joined: Fri Oct 10, 2003 10:14 am
Posts: 7
Hibernate version:
3.2.2 GA

Seems to be a small typo on line 3718 in AbstractEntityPersister (trunk and 3.2.2 GA) which makes exceptions during property generation being logged but not thrown:

Code:
      
catch( SQLException sqle ) {
         JDBCExceptionHelper.convert(
               getFactory().getSQLExceptionConverter(),
               sqle,
               "unable to select generated column values",
               selectionSQL
         );


There should be a throw in there I guess. :)

Code:
      
catch( SQLException sqle ) {
         throw JDBCExceptionHelper.convert(
               getFactory().getSQLExceptionConverter(),
               sqle,
               "unable to select generated column values",
               selectionSQL
         );


If this is intentional (might be, of course), is there any way to detect these kinds of exceptions?


Last edited by DaGGeRRz on Fri Mar 16, 2007 6:58 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 6:56 am 
Newbie

Joined: Fri Oct 10, 2003 10:14 am
Posts: 7
OK, elaborating a bit:

This bug will not be noticeable in most cases and is probably why it hasn't been detected / fixed so far. The method in question (processGeneratedProperties) is used for retrieving properties that are marked as "generated" in the mapping document / annotations - in other words any value that the database provides and is considered "read-only" from the Hibernate application's point of view.

The generated value is retrieved by an extra select statement executed by Hibernate after an entity has been inserterd and / or updated (according to how the generated property is flagged). In my particular case, a property (not a key) is marked as generated="insert", so after Hibernate inserts a new entity to the database, it will immediately do a select and set the generated property to the value the database returns.

Only in rare cases will this select fail in any way - in fact, I cannot think of any situations other than mapping errors (e.g getInt on a CHAR column) that can cause errors in this last select. That is in addition to my situation - a deadlock.

My entity class uses uuid.hex generator for the PK, but at one point, we introduced a second unique key due to purely aestethic reasons. This is a SQL Server identity column. Since we don't do any explicit table locking during the inserts, we end up with deadlocks every time the following happens:

Code:
T1: INSERT INTO TABLE (ID) values (?)
T2: INSERT INTO TABLE (ID) values (?)
T2: SELECT GENERATED_ID FROM TABLE WHERE ID = ? -- T1's insert hasn't been committed, so what should the the generated ID be? Deadlock!
T1: SELECT GENERATED_ID FROM TABLE WHERE ID = ?
...


SQL Server throws an error to indicate the deadlock, but due to the missing throw in the processGeneratedProperties-method, it is never shown to the process doing the insert. The generated property is not set and retains it's null (or 0 in case of a primitive) without the business logic ever knowing that the entity could not be saved.

Our solution to this is simple, we don't care about having "holes" in the identity sequence, so setting the transaction isolation to read_uncommited for this particular operation avoids the deadlock. BUT, it still seems like this is a bug. :)

I'll try follow policy and not report this on Jira until I'm told, but I'm hoping one of the devs could comment on this now. :)

Cheers,

Dag


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.