componentPath += tokens.nextToken(); final Type type = provider.getType( componentPath ); if ( type.isAssociationType() ) { final CollectionType ctype = type.isCollectionType() ? (CollectionType)type : null; final Type elementType = (ctype != null) ? ctype.getElementType( sessionFactory ) : null; if ( ctype != null && elementType.isComponentType() ) { provider = new ComponentCollectionCriteriaInfoProvider( helper.getCollectionPersister(ctype.getRole()) ); else if ( ctype != null && !elementType.isEntityType() ) { provider = new ScalarCollectionCriteriaInfoProvider( helper, ctype.getRole() ); (Queryable) sessionFactory.getEntityPersister( atype.getAssociatedEntityName( sessionFactory ) ) );
final EntityPersister ownerPersister = collectionPersister.getOwnerEntityPersister(); if ( ownerPersister.getIdentifierType().getReturnedClass().isInstance( key ) ) { return getEntity( session.generateEntityKey( key, collectionPersister.getOwnerEntityPersister() ) ); if ( ownerPersister.isInstance( key ) ) { final Serializable owenerId = ownerPersister.getIdentifier( key, session ); if ( owenerId == null ) { return null; final CollectionType collectionType = collectionPersister.getCollectionType(); if ( collectionType.getLHSPropertyName() != null ) { final Object owner = getEntity( new EntityUniqueKey( ownerPersister.getEntityName(), collectionType.getLHSPropertyName(), key, collectionPersister.getKeyType(), final Serializable ownerId = ownerPersister.getIdByUniqueKey( key, collectionType.getLHSPropertyName(), session ); return getEntity( session.generateEntityKey( ownerId, ownerPersister ) );
@Override public void beforeInitialize(CollectionPersister persister, int anticipatedSize) { this.map = (Map) persister.getCollectionType().instantiate( anticipatedSize ); }
@Override public Object resolve(Object value, SharedSessionContractImplementor session, Object owner, Boolean overridingEager) throws HibernateException { return resolveKey( getKeyOfOwner( owner, session ), session, owner, overridingEager ); }
@Override public String getName() { return getReturnedClass().getName() + '(' + getRole() + ')'; }
@Override public Serializable disassemble(Object value, SharedSessionContractImplementor session, Object owner) throws HibernateException { //remember the uk value //This solution would allow us to eliminate the owner arg to disassemble(), but //what if the collection was null, and then later had elements added? seems unsafe //session.getPersistenceContext().getCollectionEntry( (PersistentCollection) value ).getKey(); final Serializable key = getKeyOfOwner(owner, session); if (key==null) { return null; } else { return getPersister(session) .getKeyType() .disassemble( key, session, owner ); } }
final Object anything) throws HibernateException { if ( persister.hasCascades() || action.requiresNoCascadeChecking() ) { // performance opt final boolean traceEnabled = LOG.isTraceEnabled(); if ( traceEnabled ) { LOG.tracev( "Processing cascade {0} for: {1}", action, persister.getEntityName() ); final Type[] types = persister.getPropertyTypes(); final String[] propertyNames = persister.getPropertyNames(); final CascadeStyle[] cascadeStyles = persister.getPropertyCascadeStyles(); if ( types[ i ].isCollectionType() ) { child = collectionType.getCollection( collectionType.getKeyOfOwner( parent, eventSource ), eventSource, parent, ); else if ( types[ i ].isComponentType() ) { ); else if ( action.performOnLazyProperty() && types[ i ].isEntityType() ) {
private void addParentChildEntityNameByPropertyAndValue(AbstractEntityInsertAction action, BatchIdentifier batchIdentifier, Type type, Object value) { if ( type.isEntityType() ) { final EntityType entityType = (EntityType) type; final String entityName = entityType.getName(); final String rootEntityName = action.getSession().getFactory().getMetamodel().entityPersister( entityName ).getRootEntityName(); else if ( type.isCollectionType() ) { CollectionType collectionType = (CollectionType) type; final SessionFactoryImplementor sessionFactory = ( (SessionImplementor) action.getSession() ) .getSessionFactory(); if ( collectionType.getElementType( sessionFactory ).isEntityType() && !sessionFactory.getMetamodel().collectionPersister( collectionType.getRole() ).isManyToMany() ) { String entityName = collectionType.getAssociatedEntityName( sessionFactory ); String rootEntityName = action.getSession().getFactory().getMetamodel().entityPersister( entityName ).getRootEntityName(); batchIdentifier.getChildEntityNames().add( entityName ); if ( !rootEntityName.equals( entityName ) ) {
private void addAssociationsToTheSetForOneProperty(String name, Type type, String prefix, SessionFactoryImplementor factory) { if ( type.isCollectionType() ) { CollectionType collType = (CollectionType) type; Type assocType = collType.getElementType( factory ); addAssociationsToTheSetForOneProperty(name, assocType, prefix, factory); } //ToOne association else if ( type.isEntityType() || type.isAnyType() ) { associations.add( prefix + name ); } else if ( type.isComponentType() ) { CompositeType componentType = (CompositeType) type; addAssociationsToTheSetForAllProperties( componentType.getPropertyNames(), componentType.getSubtypes(), (prefix.equals( "" ) ? name : prefix + name) + ".", factory); } }
@Override public String toLoggableString(Object value, SessionFactoryImplementor factory) throws HibernateException { if ( value == null ) { return "null"; } if ( !getReturnedClass().isInstance( value ) && !PersistentCollection.class.isInstance( value ) ) { // its most likely the collection-key final CollectionPersister persister = getPersister( factory ); if ( persister.getKeyType().getReturnedClass().isInstance( value ) ) { return getRole() + "#" + getPersister( factory ).getKeyType().toLoggableString( value, factory ); } else { // although it could also be the collection-id if ( persister.getIdentifierType() != null && persister.getIdentifierType().getReturnedClass().isInstance( value ) ) { return getRole() + "#" + getPersister( factory ).getIdentifierType().toLoggableString( value, factory ); } } } return renderLoggableString( value, factory ); }
private boolean hasInverseCollection(ClassMetadata meta, Class<?> elementType) { SessionFactoryImplementor impl = (SessionFactoryImplementor) sessionFactory; for (Type type : meta.getPropertyTypes()) { if (type.isCollectionType()) { String role = ((CollectionType) type).getRole(); CollectionPersister persister = impl.getCollectionPersister(role); return persister.isInverse() && persister.getElementType() .getReturnedClass().equals(elementType); } } return false; }
final Object anything, final CollectionType type) { final CollectionPersister persister = eventSource.getFactory().getCollectionPersister( type.getRole() ); final Type elemType = persister.getElementType(); if ( elemType.isEntityType() || elemType.isAnyType() || elemType.isComponentType() ) { cascadeCollectionElements( action, elemType, anything, persister.isCascadeDeleteEnabled() );
CollectionReturn collRtn = (CollectionReturn) ownerDescriptor; String role = collRtn.getOwnerEntityName() + "." + collRtn.getOwnerProperty(); CollectionPersister persister = getFactory().getMetamodel().collectionPersister( role ); EntityType ownerType = (EntityType) persister.getElementType(); entityName = ownerType.getAssociatedEntityName( getFactory() ); Queryable persister = determineAppropriateOwnerPersister( fetchRtn.getOwner() ); Type ownerType = persister.getPropertyType( fetchRtn.getOwnerProperty() ); if ( ownerType.isEntityType() ) { entityName = ( (EntityType) ownerType ).getAssociatedEntityName( getFactory() ); else if ( ownerType.isCollectionType() ) { Type ownerCollectionElementType = ( (CollectionType) ownerType ).getElementType( getFactory() ); if ( ownerCollectionElementType.isEntityType() ) { entityName = ( (EntityType) ownerCollectionElementType ).getAssociatedEntityName( getFactory() ); return (Queryable) getFactory().getMetamodel().entityPersister( entityName );
private void evictCachedCollections(Type[] types, Serializable id, EventSource source) throws HibernateException { for ( Type type : types ) { if ( type.isCollectionType() ) { CollectionPersister collectionPersister = source.getFactory().getMetamodel().collectionPersister( ( (CollectionType) type ).getRole() ); if ( collectionPersister.hasCache() ) { final CollectionDataAccess cache = collectionPersister.getCacheAccessStrategy(); final Object ck = cache.generateCacheKey( id, collectionPersister, source.getFactory(), source.getTenantIdentifier() ); final SoftLock lock = cache.lockItem( source, ck, null ); cache.remove( source, ck ); source.getActionQueue().registerProcess( (success, session) -> cache.unlockItem( session, ck, lock ) ); } } else if ( type.isComponentType() ) { CompositeType actype = (CompositeType) type; evictCachedCollections( actype.getSubtypes(), id, source ); } } } }
private boolean isNonIdentifierWhereConditionsRequired(String entityName, String propertyName, SessionImplementor session) { final Type propertyType = session.getSessionFactory().getMetamodel().entityPersister( entityName ).getPropertyType( propertyName ); if ( propertyType.isCollectionType() ) { final CollectionType collectionType = (CollectionType) propertyType; final Type collectionElementType = collectionType.getElementType( session.getSessionFactory() ); if ( collectionElementType instanceof ComponentType ) { // required for Embeddables return true; } else if ( collectionElementType instanceof MaterializedClobType || collectionElementType instanceof MaterializedNClobType ) { // for Map<> using @Lob annotations return collectionType instanceof MapType; } } return false; } }
if ( type.isCollectionType() ) { CollectionType cType = (CollectionType) type; AbstractCollectionPersister cPersister = (AbstractCollectionPersister) factory.getMetamodel().collectionPersister( cType.getRole() ); if ( cPersister.isManyToMany() ) { deletes.add( generateDelete(
protected QueryableCollection getQueryableCollection( String entityName, String propertyName, SessionFactoryImplementor factory) throws HibernateException { final PropertyMapping ownerMapping = (PropertyMapping) factory.getEntityPersister( entityName ); final Type type = ownerMapping.toType( propertyName ); if ( !type.isCollectionType() ) { throw new MappingException( "Property path [" + entityName + "." + propertyName + "] does not reference a collection" ); } final String role = ( (CollectionType) type ).getRole(); try { return (QueryableCollection) factory.getCollectionPersister( role ); } catch ( ClassCastException cce ) { throw new QueryException( "collection role is not queryable: " + role ); } catch ( Exception e ) { throw new QueryException( "collection role not found: " + role ); } }
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() ); } }
if ( type.isCollectionType() ) { final CollectionPersister persister = factory.getMetamodel().collectionPersister( collectionType.getRole() ); PersistentCollection collection = session.getPersistenceContext().getCollection( new CollectionKey( persister, key ) ); if ( collection == null ) { collection = collectionType.instantiate( session, persister, key ); collection.setOwner( entity ); session.getPersistenceContext().addUninitializedCollection( persister, collection, key ); if ( !persister.isExtraLazy() ) { session.initializeCollection( collection, false ); if ( collectionType.isArrayType() ) { session.getPersistenceContext().addCollectionHolder( collection );
if ( propertyType.isComponentType() ) { return checkComponentNullability( value, (CompositeType) propertyType ); if ( propertyType.isCollectionType() ) { final Type collectionElementType = collectionType.getElementType( session.getFactory() ); if ( collectionElementType.isComponentType() ) {