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

Dave Copeland (JIRA) noreply at atlassian.com
Thu May 8 17:42:33 EDT 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2382?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_30148 ] 

Dave Copeland commented on HHH-2382:
------------------------------------

I have experienced this problem running outside of an EJB container (running in Tomcat).  The solution was to run inside a transaction, vi EntityManager.getTransaction().  Well, more of a workaround.  Keep in mind that there's another bug where child entities are inserted with null foreign keys so your database has to allow null on all foreign keys.

> 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
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.2.0.ga, 3.2.1, 3.2.2
>            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