/** * Whether the association in question is stored within an entity structure ("embedded") and this entity has * properties whose value is generated in the datastore (such as a version attribute) or not. * * @return {@code true} in case the represented association is stored within an entity which has server-generated * properties, and thus must be re-read after an update to the association, {@code false} otherwise. */ public boolean hostingEntityRequiresReadAfterUpdate() { if ( hostingEntityRequiresReadAfterUpdate == null ) { boolean storedInEntityStructure = gridDialect.isStoredInEntityStructure( associationKeyMetadata, associationTypeContext ); boolean hasUpdateGeneratedProperties = getHostingEntityPersister().hasUpdateGeneratedProperties(); hostingEntityRequiresReadAfterUpdate = storedInEntityStructure && hasUpdateGeneratedProperties; } return hostingEntityRequiresReadAfterUpdate; }
public AssociationKey getAssociationKey() { if ( associationKey == null ) { final Object[] columnValues = getKeyColumnValues(); EntityKey ownerEntityKey; if ( key != null ) { ownerEntityKey = EntityKeyBuilder.fromPersister( (OgmEntityPersister) getHostingEntityPersister(), (Serializable) key, session ); } else { ownerEntityKey = new EntityKey( ( (OgmEntityPersister) getHostingEntityPersister() ).getEntityKeyMetadata(), columnValues ); } associationKey = new AssociationKey( associationKeyMetadata, columnValues, ownerEntityKey ); } return associationKey; }
/** * Reads the entity hosting the association from the datastore and applies any property changes from the server * side. */ private void updateHostingEntityIfRequired() { if ( hostingEntity != null && hostingEntityRequiresReadAfterUpdate() ) { OgmEntityPersister entityPersister = getHostingEntityPersister(); if ( GridDialects.hasFacet( gridDialect, GroupingByEntityDialect.class ) ) { ( (GroupingByEntityDialect) gridDialect ).flushPendingOperations( getAssociationKey().getEntityKey(), entityPersister.getTupleContext( session ) ); } entityPersister.processUpdateGeneratedProperties( entityPersister.getIdentifier( hostingEntity, session ), hostingEntity, new Object[entityPersister.getPropertyNames().length], session ); } }