private Integer locateKeyManyToOneTargetIndex(OuterJoinableAssociation joinWithCompositeId, EntityType keyManyToOneType) { // the lhs (if one) is a likely candidate if ( joinWithCompositeId.getLhsAlias() != null ) { final OuterJoinableAssociation lhs = associationsByAlias.get( joinWithCompositeId.getLhsAlias() ); if ( keyManyToOneType.getAssociatedEntityName( factory ).equals( lhs.getJoinableType().getAssociatedEntityName( factory ) ) ) { return positionsByAlias.get( lhs.getRhsAlias() ); } } // otherwise, seek out OuterJoinableAssociation which are RHS of given OuterJoinableAssociation // (joinWithCompositeId) for ( OuterJoinableAssociation oja : associationsByAlias.values() ) { if ( oja.getLhsAlias() != null && oja.getLhsAlias().equals( joinWithCompositeId.getRhsAlias() ) ) { if ( keyManyToOneType.equals( oja.getJoinableType() ) ) { return positionsByAlias.get( oja.getLhsAlias() ); } } } return null; } }
private static EntityPersister resolveEntityPersister( Object entity, AssociationType associationType, SharedSessionContractImplementor session, SessionFactoryImplementor sessionFactory) { assert sessionFactory != null; if ( session != null ) { return session.getEntityPersister( associationType.getAssociatedEntityName( session.getFactory() ), entity ); } String entityName = null; for ( EntityNameResolver entityNameResolver : sessionFactory.getMetamodel().getEntityNameResolvers() ) { entityName = entityNameResolver.resolveEntityName( entity ); if ( entityName != null ) { break; } } if ( entityName == null ) { // old fall-back entityName = entity.getClass().getName(); } return sessionFactory.getMetamodel().entityPersister( entityName ); }
(Queryable) sessionFactory.getEntityPersister( atype.getAssociatedEntityName( sessionFactory ) ) );
Type indexType = persister.getIndexType(); if ( indexType != null && indexType.isAssociationType() && !indexType.isAnyType() ) { String entityName = ( (AssociationType) indexType ).getAssociatedEntityName( sessionFactory ); Set<String> roles = collectionRolesByEntityParticipant.get( entityName ); if ( roles == null ) { String entityName = ( ( AssociationType ) elementType ).getAssociatedEntityName( sessionFactory ); Set<String> roles = collectionRolesByEntityParticipant.get( entityName ); if ( roles == null ) {
@Override public EntityDelegate getAssociatedEntityDelegate() { String entityName = ((AssociationType)this.propertType).getAssociatedEntityName(this.factory); return new EntityDelegateImpl(this.factory.getEntityPersister(entityName)); } }
private Integer locateKeyManyToOneTargetIndex(OuterJoinableAssociation joinWithCompositeId, EntityType keyManyToOneType) { // the lhs (if one) is a likely candidate if ( joinWithCompositeId.getLhsAlias() != null ) { final OuterJoinableAssociation lhs = associationsByAlias.get( joinWithCompositeId.getLhsAlias() ); if ( keyManyToOneType.getAssociatedEntityName( factory ).equals( lhs.getJoinableType().getAssociatedEntityName( factory ) ) ) { return positionsByAlias.get( lhs.getRhsAlias() ); } } // otherwise, seek out OuterJoinableAssociation which are RHS of given OuterJoinableAssociation // (joinWithCompositeId) for ( OuterJoinableAssociation oja : associationsByAlias.values() ) { if ( oja.getLhsAlias() != null && oja.getLhsAlias().equals( joinWithCompositeId.getRhsAlias() ) ) { if ( keyManyToOneType.equals( oja.getJoinableType() ) ) { return positionsByAlias.get( oja.getLhsAlias() ); } } } return null; } }
private Integer locateKeyManyToOneTargetIndex(OuterJoinableAssociation joinWithCompositeId, EntityType keyManyToOneType) { // the lhs (if one) is a likely candidate if ( joinWithCompositeId.getLhsAlias() != null ) { final OuterJoinableAssociation lhs = associationsByAlias.get( joinWithCompositeId.getLhsAlias() ); if ( keyManyToOneType.getAssociatedEntityName( factory ).equals( lhs.getJoinableType().getAssociatedEntityName( factory ) ) ) { return positionsByAlias.get( lhs.getRhsAlias() ); } } // otherwise, seek out OuterJoinableAssociation which are RHS of given OuterJoinableAssociation // (joinWithCompositeId) for ( OuterJoinableAssociation oja : associationsByAlias.values() ) { if ( oja.getLhsAlias() != null && oja.getLhsAlias().equals( joinWithCompositeId.getRhsAlias() ) ) { if ( keyManyToOneType.equals( oja.getJoinableType() ) ) { return positionsByAlias.get( oja.getLhsAlias() ); } } } return null; } }
private String getPathEntityName(String path) { Queryable persister = (Queryable) sessionFactory.getEntityPersister(rootEntityName); StringTokenizer tokens = new StringTokenizer(path, "."); String componentPath = ""; while ( tokens.hasMoreTokens() ) { componentPath += tokens.nextToken(); Type type = persister.toType(componentPath); if ( type.isAssociationType() ) { AssociationType atype = (AssociationType) type; persister = (Queryable) sessionFactory.getEntityPersister( atype.getAssociatedEntityName(sessionFactory) ); componentPath = ""; } else if ( type.isComponentType() ) { componentPath += '.'; } else { throw new QueryException("not an association: " + componentPath); } } return persister.getEntityName(); }
private String getPathEntityName(String path) { Queryable persister = ( Queryable ) sessionFactory.getEntityPersister( rootEntityName ); StringTokenizer tokens = new StringTokenizer( path, "." ); String componentPath = ""; while ( tokens.hasMoreTokens() ) { componentPath += tokens.nextToken(); Type type = persister.toType( componentPath ); if ( type.isAssociationType() ) { AssociationType atype = ( AssociationType ) type; persister = ( Queryable ) sessionFactory.getEntityPersister( atype.getAssociatedEntityName( sessionFactory ) ); componentPath = ""; } else if ( type.isComponentType() ) { componentPath += '.'; } else { throw new QueryException( "not an association: " + componentPath ); } } return persister.getEntityName(); }
@Override @SuppressWarnings("deprecation") public Class getAssociatedClass(final SessionFactoryImplementor factory) throws MappingException { try { final org.hibernate.SessionFactory sessionFactory = HibernateBridge.get(factory).getV5SessionFactory(); final org.hibernate.engine.spi.SessionFactoryImplementor sessionFactoryImpl = (org.hibernate.engine.spi.SessionFactoryImplementor) sessionFactory; final String entityName = type.getAssociatedEntityName(sessionFactoryImpl); return sessionFactoryImpl.getEntityPersister(entityName).getMappedClass(); } catch (final org.hibernate.MappingException ex) { throw (MappingException) HibernateExceptionAdapter.adapt(ex); } } }
private boolean hasImplicitCollectionJoins0(CompositeType compositeType, Map<String, Boolean> contextMap) { Type[] subtypes = compositeType.getSubtypes(); for (int i = subtypes.length - 1; i >= 0; i--) { Type subtype = subtypes[i]; if (compositeType.getFetchMode(i) == FetchMode.JOIN) { if (subtype.isCollectionType()) { //find collection with {fetch = "join"} return true; } if (subtype instanceof AssociationType) { String childEntityName = ((AssociationType)subtype).getAssociatedEntityName(this.factory); if (this.hasImplicitCollectionJoins0(childEntityName, contextMap)) { return true; } } } else if (subtype instanceof CompositeType) { if (this.hasImplicitCollectionJoins0((CompositeType)subtype, contextMap)) { return true; } } } return false; }
JoinSource joinSource = (JoinSource)e2.getValue(); if (joinSource.parentAlias.equals(e1.getKey())) { String entityName = ((AssociationType)parentEntityPersister.getPropertyType(joinSource.assocationName)).getAssociatedEntityName(sfi); EntityPersister entityPersister = sfi.getEntityPersister(entityName); e2.setValue(entityPersister);
Type indexType = persister.getIndexType(); if ( indexType != null && indexType.isAssociationType() && !indexType.isAnyType() ) { String entityName = ( ( AssociationType ) indexType ).getAssociatedEntityName( this ); Set roles = ( Set ) tmpEntityToCollectionRoleMap.get( entityName ); if ( roles == null ) { String entityName = ( ( AssociationType ) elementType ).getAssociatedEntityName( this ); Set roles = ( Set ) tmpEntityToCollectionRoleMap.get( entityName ); if ( roles == null ) {
@Override public ConstraintType requiresTreatFilter(EntityType<?> ownerType, String attributeName, JoinType joinType) { // When we don't support treat joins(Hibernate 4.2), we need to put the constraints into the WHERE clause if (!supportsTreatJoin() && joinType == JoinType.INNER) { return ConstraintType.WHERE; } AbstractEntityPersister persister = getEntityPersister(ownerType); Type propertyType = persister.getPropertyType(attributeName); if (!(propertyType instanceof AssociationType)) { return ConstraintType.NONE; } // When the inner treat joined element is collection, we always need the constraint, see HHH-??? TODO: report issue if (propertyType instanceof CollectionType) { if (joinType == JoinType.INNER) { if (isForeignKeyDirectionToParent((CollectionType) propertyType)) { return ConstraintType.WHERE; } return ConstraintType.ON; } else if (!((CollectionType) propertyType).getElementType(persister.getFactory()).isEntityType()) { return ConstraintType.NONE; } } String propertyEntityName = ((AssociationType) propertyType).getAssociatedEntityName(persister.getFactory()); AbstractEntityPersister propertyTypePersister = (AbstractEntityPersister) entityPersisters.get(propertyEntityName); // When the treat joined element is a union subclass, we always need the constraint, see HHH-??? TODO: report issue if (propertyTypePersister instanceof UnionSubclassEntityPersister) { return ConstraintType.ON; } return ConstraintType.NONE; }
atype.getAssociatedEntityName( sessionFactory ) ));
atype.getAssociatedEntityName( sessionFactory ) ));
propertyEntityType = associationPropertyType.getAssociatedEntityName( getSessionFactory() ); currentPersister = getPersister( propertyEntityType ); String targetNodeType = currentPersister.getEntityKeyMetadata().getTable();
private boolean hasImplicitCollectionJoins1(String entityName, Map<String, Boolean> contextMap) { EntityPersister persister = this.factory.getEntityPersister(entityName); for (NonIdentifierAttribute nonIdAttribute : persister.getEntityMetamodel().getProperties()) { Type propertyType = nonIdAttribute.getType(); if (nonIdAttribute.getFetchMode() == FetchMode.JOIN) { if (propertyType.isCollectionType()) { //find collection with {fetch = "join"} return true; } if (propertyType instanceof AssociationType) { String childEntityName = ((AssociationType)propertyType).getAssociatedEntityName(this.factory); if (this.hasImplicitCollectionJoins0(childEntityName, contextMap)) { return true; } } } else if (propertyType instanceof CompositeType) { if (this.hasImplicitCollectionJoins0((CompositeType)propertyType, contextMap)) { return true; } } } return false; }
Type indexType = persister.getIndexType(); if ( indexType != null && indexType.isAssociationType() && !indexType.isAnyType() ) { String entityName = ( ( AssociationType ) indexType ).getAssociatedEntityName( this ); Set roles = tmpEntityToCollectionRoleMap.get( entityName ); if ( roles == null ) { String entityName = ( ( AssociationType ) elementType ).getAssociatedEntityName( this ); Set roles = tmpEntityToCollectionRoleMap.get( entityName ); if ( roles == null ) {
String associatedEntity = assType.getAssociatedEntityName((SessionFactoryImplementor) sessionFactory); ClassMetadata associatedMetaData = sessionFactory.getClassMetadata(associatedEntity); prop.setRelatedClassType(associatedMetaData.getMappedClass(EntityMode.POJO));