|
11 | 11 | import java.sql.ResultSet;
|
12 | 12 | import java.sql.SQLException;
|
13 | 13 |
|
| 14 | +import org.hibernate.AssertionFailure; |
14 | 15 | import org.hibernate.HibernateException;
|
15 | 16 | import org.hibernate.MappingException;
|
| 17 | +import org.hibernate.engine.internal.ForeignKeys; |
16 | 18 | import org.hibernate.engine.jdbc.Size;
|
17 | 19 | import org.hibernate.engine.spi.EntityKey;
|
18 | 20 | import org.hibernate.engine.spi.Mapping;
|
@@ -188,15 +190,32 @@ public boolean useLHSPrimaryKey() {
|
188 | 190 |
|
189 | 191 | @Override
|
190 | 192 | 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 ); |
192 | 207 | }
|
193 | 208 |
|
194 | 209 | @Override
|
195 | 210 | 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 ); |
200 | 219 | }
|
201 | 220 |
|
202 | 221 | /**
|
|
0 commit comments