[hibernate-issues] [Hibernate-JIRA] Closed: (HHH-1336) ForeignGenerator does not handle transient entities with an entity-name properly

Steve Ebersole (JIRA) noreply at atlassian.com
Mon Mar 21 13:00:43 EDT 2011


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1336?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Steve Ebersole closed HHH-1336.
-------------------------------


Closing stale resolved issues

> ForeignGenerator does not handle transient entities with an entity-name properly
> --------------------------------------------------------------------------------
>
>                 Key: HHH-1336
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1336
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.1
>         Environment: Hibernate 3.1, any platform/database
>            Reporter: Paul Andrews
>            Assignee: Steve Ebersole
>            Priority: Minor
>             Fix For: 3.1.1
>
>
> I have an entity that has a one-to-one relationship with another entity, i.e. (ommitting a bunch of mandatory stuff for the sake of brevity): 
> <class entity-name="AnEntity"> 
>   <id name="primaryKey"> 
>     <generator class="foreign"> 
>       <param name="property">aProperty</param> 
>     </generator> 
>   </id> 
>   <one-to-one name="aProperty" entity-name="AnotherEntity"/> 
> </class> 
> I then create a detached (aka transient) instance of AnEntity with an embedded detached instance of AnotherEntity with both of their id's set to null and then do a saveOrUpdate(). Hibernate then throws an 'unknown entity mapping' exception with the classname of the instance of AnotherEntity. In other words it is looking for a mapping for the actual class name of the associated entity when it should be looking for a mapping for the entity-name of the associated entity.
> Tracing into the code ForeignGenerator.generate() calls session.save as follows: 
>   Serializable id; 
>   try { 
>    id = ForeignKeys.getEntityIdentifierIfNotUnsaved( 
>     type.getAssociatedEntityName(), 
>     associatedObject, 
>     sessionImplementor); 
>   } catch (TransientObjectException toe) { 
>     id = session.save(associatedObject); 
>   } 
> Modifying the session.save() call as follows seems to fix the problem: 
>   Serializable id; 
>   try { 
>    id = ForeignKeys.getEntityIdentifierIfNotUnsaved( 
>     type.getAssociatedEntityName(), 
>     associatedObject, 
>     sessionImplementor); 
>   } catch (TransientObjectException toe) { 
>     id = session.save(type.getAssociatedEntityName(), associatedObject); 
>   } 
>  

-- 
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