Skip to content

Commit

Permalink
HHH-14216 Fix the assemble/disassemble methods of the OneToOneType.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Ellingsworth authored and sebersole committed Nov 4, 2020
1 parent aec21d2 commit ef5c944
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java
Expand Up @@ -11,8 +11,10 @@
import java.sql.ResultSet;
import java.sql.SQLException;

import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.engine.internal.ForeignKeys;
import org.hibernate.engine.jdbc.Size;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.Mapping;
Expand Down Expand Up @@ -188,15 +190,32 @@ public boolean useLHSPrimaryKey() {

@Override
public Serializable disassemble(Object value, SharedSessionContractImplementor session, Object owner) throws HibernateException {
return null;
if (value == null) {
return null;
}

Object id = ForeignKeys.getEntityIdentifierIfNotUnsaved( getAssociatedEntityName(), value, session );

if ( id == null ) {
throw new AssertionFailure(
"cannot cache a reference to an object with a null id: " +
getAssociatedEntityName()
);
}

return getIdentifierType( session ).disassemble( id, session, owner );
}

@Override
public Object assemble(Serializable oid, SharedSessionContractImplementor session, Object owner) throws HibernateException {
//this should be a call to resolve(), not resolveIdentifier(),
//'cos it might be a property-ref, and we did not cache the
//referenced value
return resolve( session.getContextEntityIdentifier(owner), session, owner );
//the owner of the association is not the owner of the id
Serializable id = ( Serializable ) getIdentifierType( session ).assemble( oid, session, null );

if ( id == null ) {
return null;
}

return resolveIdentifier( id, session );
}

/**
Expand Down

0 comments on commit ef5c944

Please sign in to comment.