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):
Code:
<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. Tracing into the code ForeignGenerator.generate() calls session.save as follows:
Code:
Serializable id;
try {
id = ForeignKeys.getEntityIdentifierIfNotUnsaved(
type.getAssociatedEntityName(),
associatedObject,
sessionImplementor);
} catch (TransientObjectException toe) {
id = session.save(associatedObject);
}
If looks like if it were modified as follows, it might work?
Code:
Serializable id;
try {
id = ForeignKeys.getEntityIdentifierIfNotUnsaved(
type.getAssociatedEntityName(),
associatedObject,
sessionImplementor);
} catch (TransientObjectException toe) {
id = session.save(type.getAssociatedEntityName(), associatedObject);
}