/** * Is the owning entity versioned? * * @param session The session from which the request is originating. * @return True if the collection owner is versioned; false otherwise. * @throws org.hibernate.MappingException Indicates our persister could not be located. */ private boolean isOwnerVersioned(SharedSessionContractImplementor session) throws MappingException { return getPersister( session ).getOwnerEntityPersister().isVersioned(); }
private static void addIdToCollectionInfoString( CollectionPersister persister, Serializable id, SessionFactoryImplementor factory, StringBuilder s ) { // Need to use the identifier type of the collection owner // since the incoming is value is actually the owner's id. // Using the collection's key type causes problems with // property-ref keys. // Also need to check that the expected identifier type matches // the given ID. Due to property-ref keys, the collection key // may not be the owner key. Type ownerIdentifierType = persister.getOwnerEntityPersister() .getIdentifierType(); if ( id.getClass().isAssignableFrom( ownerIdentifierType.getReturnedClass() ) ) { s.append( ownerIdentifierType.toLoggableString( id, factory ) ); } else { // TODO: This is a crappy backup if a property-ref is used. // If the reference is an object w/o toString(), this isn't going to work. s.append( id.toString() ); } }
protected Serializable getCollectionKey( CollectionPersister persister, Object owner, EntityEntry ownerEntry, SharedSessionContractImplementor session) { final CollectionType collectionType = persister.getCollectionType(); if ( ownerEntry != null ) { // this call only works when the owner is associated with the Session, which is not always the case return collectionType.getKeyOfOwner( owner, session ); } if ( collectionType.getLHSPropertyName() == null ) { // collection key is defined by the owning entity identifier return persister.getOwnerEntityPersister().getIdentifier( owner, session ); } else { return (Serializable) persister.getOwnerEntityPersister().getPropertyValue( owner, collectionType.getLHSPropertyName() ); } }
s.append( '#' ); Type ownerIdentifierType = persister.getOwnerEntityPersister() .getIdentifierType(); Serializable ownerKey;
public CollectionKey(CollectionPersister persister, Serializable key) { this( persister.getRole(), key, persister.getKeyType(), persister.getOwnerEntityPersister().getEntityMetamodel().getEntityMode(), persister.getFactory() ); }
protected static String getAffectedOwnerEntityName(CollectionPersister collectionPersister, Object affectedOwner, EventSource source ) { // collectionPersister should not be null, but we don't want to throw // an exception if it is null String entityName = ( collectionPersister == null ? null : collectionPersister.getOwnerEntityPersister().getEntityName() ); if ( affectedOwner != null ) { EntityEntry ee = source.getPersistenceContext().getEntry( affectedOwner ); if ( ee != null && ee.getEntityName() != null) { entityName = ee.getEntityName(); } } return entityName; }
/** * Get the id value from the owning entity key, usually the same as the key, but might be some * other property, in the case of property-ref * * @param key The collection owner key * @param session The session from which the request is originating. * @return The collection owner's id, if it can be obtained from the key; * otherwise, null is returned */ public Serializable getIdOfOwnerOrNull(Serializable key, SharedSessionContractImplementor session) { Serializable ownerId = null; if ( foreignKeyPropertyName == null ) { ownerId = key; } else { Type keyType = getPersister( session ).getKeyType(); EntityPersister ownerPersister = getPersister( session ).getOwnerEntityPersister(); // TODO: Fix this so it will work for non-POJO entity mode Class ownerMappedClass = ownerPersister.getMappedClass(); if ( ownerMappedClass.isAssignableFrom( keyType.getReturnedClass() ) && keyType.getReturnedClass().isInstance( key ) ) { // the key is the owning entity itself, so get the ID from the key ownerId = ownerPersister.getIdentifier( key, session ); } else { // TODO: check if key contains the owner ID } } return ownerId; }
/** * This version is slightly different for say * {@link org.hibernate.type.CollectionType#getKeyOfOwner} in that here we * need to assume that the owner is not yet associated with the session, * and thus we cannot rely on the owner's EntityEntry snapshot... * * @param role The persister for the collection role being processed. * * @return The value from the owner that identifies the grouping into the collection */ final Serializable extractCollectionKeyFromOwner(CollectionPersister role) { if ( role.getCollectionType().useLHSPrimaryKey() ) { return ownerIdentifier; } return (Serializable) role.getOwnerEntityPersister().getPropertyValue( owner, role.getCollectionType().getLHSPropertyName() ); } }
persister, lce.getKey(), persister.getOwnerEntityPersister().getEntityMetamodel().getEntityMode() ), lce.getCollection()
final EntityPersister ownerPersister = collectionPersister.getOwnerEntityPersister(); if ( ownerPersister.getIdentifierType().getReturnedClass().isInstance( key ) ) { return getEntity( session.generateEntityKey( key, collectionPersister.getOwnerEntityPersister() ) ); return getEntity( session.generateEntityKey( key, collectionPersister.getOwnerEntityPersister() ) );
persister.getOwnerEntityPersister().getInstrumentationMetadata(); if ( bytecodeEnhancementMetadata.isEnhancedForLazyLoading() ) { persister.getOwnerEntityPersister().getEntityName().length() ) { persister.getOwnerEntityPersister().getEntityName().length() + 1 ); if ( !bytecodeEnhancementMetadata.isAttributeLoaded( lce.getCollection().getOwner(), propertyName ) ) { int propertyIndex = persister.getOwnerEntityPersister().getEntityMetamodel().getPropertyIndex( propertyName ); persister.getOwnerEntityPersister().setPropertyValue( lce.getCollection().getOwner(), propertyIndex,
Serializable ownerId = loadedPersister.getOwnerEntityPersister().getIdentifier( coll.getOwner(), session ); if ( ownerId == null ) { final EntityKey key = session.generateEntityKey( ownerId, loadedPersister.getOwnerEntityPersister() ); final Object owner = persistenceContext.getEntity( key ); if ( owner == null ) {
final EntityMode entityMode = persister.getOwnerEntityPersister().getEntityMode();
final EntityMode em = persister.getOwnerEntityPersister().getEntityMetamodel().getEntityMode(); final CollectionKey collectionKey = new CollectionKey( persister, key, em ); if ( LOG.isTraceEnabled() ) {
final boolean isBytecodeEnhanced = persister.getOwnerEntityPersister().getInstrumentationMetadata().isEnhancedForLazyLoading(); if ( isBytecodeEnhanced && !collection.wasInitialized() ) {
final Object linkedOwner = lce.getCollection().getOwner(); if ( linkedOwner != null ) { final Serializable ownerKey = persister.getOwnerEntityPersister().getIdentifier( linkedOwner, session ); collectionOwner = getLoadContext().getPersistenceContext().getCollectionOwner( ownerKey, persister );
/** * Is the owning entity versioned? */ private boolean isOwnerVersioned(SessionImplementor session) throws MappingException { return getPersister( session ) .getOwnerEntityPersister() .isVersioned(); }
/** * Is the owning entity versioned? */ private boolean isOwnerVersioned(SessionImplementor session) throws MappingException { return getPersister( session ) .getOwnerEntityPersister() .isVersioned(); }
@Override @SuppressWarnings( {"unchecked"}) public Serializable getSnapshot(CollectionPersister persister) throws HibernateException { final EntityMode entityMode = persister.getOwnerEntityPersister().getEntityMode(); ArrayList clonedList = new ArrayList( list.size() ); for ( Object element : list ) { Object deepCopy = persister.getElementType().deepCopy( element, persister.getFactory() ); clonedList.add( deepCopy ); } return clonedList; }
/** * Get the entity that owns this persistent collection */ public Object getCollectionOwner(Serializable key, CollectionPersister collectionPersister) throws MappingException { return getEntity( new EntityKey( key, collectionPersister.getOwnerEntityPersister(), session.getEntityMode() ) ); }