/** * The name of the associated entity. * * @param factory The session factory, for resolution. * * @return The associated entity name. */ @Override public String getAssociatedEntityName(SessionFactoryImplementor factory) { return getAssociatedEntityName(); }
/** * Generates a string representation of this type. * * @return string rep */ @Override public String toString() { return getClass().getName() + '(' + getAssociatedEntityName() + ')'; }
private boolean hasNonIdentifierPropertyNamedId(final EntityType entityType, final Mapping factory) { // TODO : would be great to have a Mapping#hasNonIdentifierPropertyNamedId method // I don't believe that Mapping#getReferencedPropertyType accounts for the identifier property; so // if it returns for a property named 'id', then we should have a non-id field named id try { return factory.getReferencedPropertyType( entityType.getAssociatedEntityName(), EntityPersister.ENTITY_ID ) != null; } catch (MappingException e) { return false; } }
public void remove() { if ( !single ) { throw new UnsupportedOperationException( "Not a single column hibernate query result set" ); } if ( currentResult == null ) { throw new IllegalStateException( "Called Iterator.remove() before next()" ); } if ( !( types[0] instanceof EntityType ) ) { throw new UnsupportedOperationException( "Not an entity" ); } session.delete( ( (EntityType) types[0] ).getAssociatedEntityName(), currentResult, false, null ); } }
/** * Convenience method to locate the identifier type of the associated entity. * * @param factory The mappings... * * @return The identifier type */ Type getIdentifierType(final Mapping factory) { final Type type = associatedIdentifierType; //The following branch implements a simple lazy-initialization, but rather than the canonical //form it returns the local variable to avoid a second volatile read: associatedIdentifierType //needs to be volatile as the initialization might happen by a different thread than the readers. if ( type == null ) { associatedIdentifierType = factory.getIdentifierType( getAssociatedEntityName() ); return associatedIdentifierType; } else { return type; } }
private static String resolveEntityName(PropertyData propertyData) { if ( EntityType.class.isInstance( propertyData.getType() ) ) { final EntityType entityType = (EntityType) propertyData.getType(); return entityType.getAssociatedEntityName(); } return null; }
public void createForeignKey() throws MappingException { if ( constrained && referencedPropertyName==null) { //TODO: handle the case of a foreign key to something other than the pk createForeignKeyOfEntity( ( (EntityType) getType() ).getAssociatedEntityName() ); } }
protected EntityPersister getAssociatedEntityPersister(final SessionFactoryImplementor factory) { final EntityPersister persister = associatedEntityPersister; //The following branch implements a simple lazy-initialization, but rather than the canonical //form it returns the local variable to avoid a second volatile read: associatedEntityPersister //needs to be volatile as the initialization might happen by a different thread than the readers. if ( persister == null ) { associatedEntityPersister = factory.getMetamodel().entityPersister( getAssociatedEntityName() ); return associatedEntityPersister; } else { return persister; } }
private EntityPersister getEntityPersister(EntityType entityType) { return factory.getMetamodel().entityPersister( entityType.getAssociatedEntityName() ); }
/** * The name of the property on the associated entity to which our FK * refers * * @param factory The mappings... * * @return The appropriate property name. * * @throws MappingException Generally, if unable to resolve the associated entity name */ public final String getIdentifierOrUniqueKeyPropertyName(Mapping factory) throws MappingException { if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) { return factory.getIdentifierPropertyName( getAssociatedEntityName() ); } else { return uniqueKeyPropertyName; } }
protected Type requireIdentifierOrUniqueKeyType(Mapping mapping) { final Type fkTargetType = getIdentifierOrUniqueKeyType( mapping ); if ( fkTargetType == null ) { throw new MappingException( "Unable to determine FK target Type for many-to-one or one-to-one mapping: " + "referenced-entity-name=[" + getAssociatedEntityName() + "], referenced-entity-attribute-name=[" + getLHSPropertyName() + "]" ); } return fkTargetType; } }
public void createForeignKey() throws MappingException { // the case of a foreign key to something other than the pk is handled in createPropertyRefConstraints if (referencedPropertyName==null && !hasFormula() ) { createForeignKeyOfEntity( ( (EntityType) getType() ).getAssociatedEntityName() ); } }
private String getElementName(PathExpressionParser.CollectionElement element, QueryTranslatorImpl q) throws QueryException { String name; if ( element.isOneToMany ) { name = element.alias; } else { Type type = element.elementType; if ( type.isEntityType() ) { //ie. a many-to-many String entityName = ( ( EntityType ) type ).getAssociatedEntityName(); name = pathExpressionParser.continueFromManyToMany( entityName, element.elementColumns, q ); } else { throw new QueryException( "illegally dereferenced collection element" ); } } return name; }
@Override public Object resolve(Object value, SharedSessionContractImplementor session, Object owner, Boolean overridingEager) throws HibernateException { if ( value != null && !isNull( owner, session ) ) { if ( isReferenceToPrimaryKey() ) { return resolveIdentifier( (Serializable) value, session, overridingEager ); } else if ( uniqueKeyPropertyName != null ) { return loadByUniqueKey( getAssociatedEntityName(), uniqueKeyPropertyName, value, session ); } } 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; } }
@Override public BidirectionalEntityReference buildBidirectionalEntityReference( AssociationAttributeDefinition attributeDefinition, FetchStrategy fetchStrategy, EntityReference targetEntityReference) { final EntityType fetchedType = (EntityType) attributeDefinition.getType(); final EntityPersister fetchedPersister = attributeDefinition.toEntityDefinition().getEntityPersister(); if ( fetchedPersister == null ) { throw new WalkingException( String.format( "Unable to locate EntityPersister [%s] for bidirectional entity reference [%s]", fetchedType.getAssociatedEntityName(), attributeDefinition.getName() ) ); } final BidirectionalEntityReference bidirectionalEntityReference = new BidirectionalEntityReferenceImpl( this, attributeDefinition, targetEntityReference ); addBidirectionalEntityReference( bidirectionalEntityReference ); return bidirectionalEntityReference; }
private Class determineAssociatedEntityClass() { final String entityName = getAssociatedEntityName(); try { return ReflectHelper.classForName( entityName ); } catch (ClassNotFoundException cnfe) { return this.scope.getTypeConfiguration().getSessionFactory().getMetamodel().entityPersister( entityName ). getEntityTuplizer().getMappedClass(); } }
public Type getSelectType() { if ( entityType == null ) { return null; } boolean shallow = fromElement.getFromClause().getWalker().isShallowQuery(); return fromElement.getSessionFactoryHelper() .getFactory() .getTypeResolver() .getTypeFactory().manyToOne( entityType.getAssociatedEntityName(), shallow ); }
private EntityLoader createUniqueKeyLoader( Type uniqueKeyType, String[] columns, LoadQueryInfluencers loadQueryInfluencers) { if ( uniqueKeyType.isEntityType() ) { String className = ( (EntityType) uniqueKeyType ).getAssociatedEntityName(); uniqueKeyType = getFactory().getMetamodel().entityPersister( className ).getIdentifierType(); } return new EntityLoader( this, columns, uniqueKeyType, 1, LockMode.NONE, getFactory(), loadQueryInfluencers ); }
private void determineValueSelectExpressions(QueryableCollection collectionPersister, List selections) { AliasGenerator aliasGenerator = new LocalAliasGenerator( 1 ); appendSelectExpressions( collectionPersister.getElementColumnNames(), selections, aliasGenerator ); Type valueType = collectionPersister.getElementType(); if ( valueType.isAssociationType() ) { EntityType valueEntityType = (EntityType) valueType; Queryable valueEntityPersister = (Queryable) sfi().getEntityPersister( valueEntityType.getAssociatedEntityName( sfi() ) ); SelectFragment fragment = valueEntityPersister.propertySelectFragmentFragment( elementTableAlias(), null, false ); appendSelectExpressions( fragment, selections, aliasGenerator ); } }