Skip to content

Commit ef5c944

Browse files
David Ellingsworthsebersole
authored andcommitted
HHH-14216 Fix the assemble/disassemble methods of the OneToOneType.
1 parent aec21d2 commit ef5c944

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
import java.sql.ResultSet;
1212
import java.sql.SQLException;
1313

14+
import org.hibernate.AssertionFailure;
1415
import org.hibernate.HibernateException;
1516
import org.hibernate.MappingException;
17+
import org.hibernate.engine.internal.ForeignKeys;
1618
import org.hibernate.engine.jdbc.Size;
1719
import org.hibernate.engine.spi.EntityKey;
1820
import org.hibernate.engine.spi.Mapping;
@@ -188,15 +190,32 @@ public boolean useLHSPrimaryKey() {
188190

189191
@Override
190192
public Serializable disassemble(Object value, SharedSessionContractImplementor session, Object owner) throws HibernateException {
191-
return null;
193+
if (value == null) {
194+
return null;
195+
}
196+
197+
Object id = ForeignKeys.getEntityIdentifierIfNotUnsaved( getAssociatedEntityName(), value, session );
198+
199+
if ( id == null ) {
200+
throw new AssertionFailure(
201+
"cannot cache a reference to an object with a null id: " +
202+
getAssociatedEntityName()
203+
);
204+
}
205+
206+
return getIdentifierType( session ).disassemble( id, session, owner );
192207
}
193208

194209
@Override
195210
public Object assemble(Serializable oid, SharedSessionContractImplementor session, Object owner) throws HibernateException {
196-
//this should be a call to resolve(), not resolveIdentifier(),
197-
//'cos it might be a property-ref, and we did not cache the
198-
//referenced value
199-
return resolve( session.getContextEntityIdentifier(owner), session, owner );
211+
//the owner of the association is not the owner of the id
212+
Serializable id = ( Serializable ) getIdentifierType( session ).assemble( oid, session, null );
213+
214+
if ( id == null ) {
215+
return null;
216+
}
217+
218+
return resolveIdentifier( id, session );
200219
}
201220

202221
/**

0 commit comments

Comments
 (0)