[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2382) DefaultLoadEventListener#onLoad throws exception when DelayedPostInsertIdentifier is set as an entity id

Eelco Hillenius (JIRA) noreply at atlassian.com
Wed Jan 24 20:12:19 EST 2007


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2382?page=comments#action_25917 ] 

Eelco Hillenius commented on HHH-2382:
--------------------------------------

As a side note, EntityIdentityInsertAction can be improved. There is no reason why generateDelayedEntityKey should be synchronized and the isDelayed delayed test can be removed as that method is private is only called from the constructor (and isDelayed is final).

> DefaultLoadEventListener#onLoad throws exception when DelayedPostInsertIdentifier is set as an entity id
> --------------------------------------------------------------------------------------------------------
>
>          Key: HHH-2382
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2382
>      Project: Hibernate3
>         Type: Bug

>   Components: core
>     Versions: 3.2.1, 3.2.2, 3.2.0.ga
>     Reporter: Eelco Hillenius

>
>
> DefaultLoadEventListener#onLoad has this code:
>   if ( idClass != null && ! idClass.isInstance( event.getEntityId() ) ) {
>     throw new TypeMismatchException(
>       "Provided id of the wrong type. Expected: " + idClass + ", got " + event.getEntityId().getClass());
>   }
> However, EntityIdentityInsertAction has this in it's constructor:
>   delayedEntityKey = isDelayed ? generateDelayedEntityKey() : null;
> and method:
>   private synchronized EntityKey generateDelayedEntityKey() {
>     if ( !isDelayed ) {
>       throw new AssertionFailure( "cannot request delayed entity-key for non-delayed post-insert-id generation" );
>     }
>     return new EntityKey( new DelayedPostInsertIdentifier(), getPersister(), getSession().getEntityMode() );
>   }
> In case an insert is tried outside of an existing transaction users may run into this problem (like I did).
> I don't know what the best fix is. The easiest fix would be:
> Index: /Users/eelcohillenius/Documents/workspace/hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java
> ===================================================================
> --- /Users/eelcohillenius/Documents/workspace/hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java	(revision 11098)
> +++ /Users/eelcohillenius/Documents/workspace/hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java	(working copy)
> @@ -5,6 +5,7 @@
>  
>  import org.apache.commons.logging.Log;
>  import org.apache.commons.logging.LogFactory;
> +import org.hibernate.EntityMode;
>  import org.hibernate.HibernateException;
>  import org.hibernate.LockMode;
>  import org.hibernate.NonUniqueObjectException;
> @@ -10,7 +11,7 @@
>  import org.hibernate.NonUniqueObjectException;
>  import org.hibernate.PersistentObjectException;
>  import org.hibernate.TypeMismatchException;
> -import org.hibernate.EntityMode;
> +import org.hibernate.action.DelayedPostInsertIdentifier;
>  import org.hibernate.cache.CacheConcurrencyStrategy;
>  import org.hibernate.cache.CacheKey;
>  import org.hibernate.cache.entry.CacheEntry;
> @@ -82,7 +83,7 @@
>  		}
>  		else {
>  			Class idClass = persister.getIdentifierType().getReturnedClass();
> -			if ( idClass != null && ! idClass.isInstance( event.getEntityId() ) ) {
> +			if ( idClass != null && ! (idClass.isInstance( event.getEntityId() ) || event.getEntityId() instanceof DelayedPostInsertIdentifier )) {
>  				throw new TypeMismatchException(
>  						"Provided id of the wrong type. Expected: " + idClass + ", got " + event.getEntityId().getClass()
>  				);
> but that would look like a quick hack to me.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list