&& propertyType.isReferenceToPrimaryKey(); idPropertyName = propertyType.getIdentifierOrUniqueKeyPropertyName( q.getFactory() ); && propertyType.isReferenceToPrimaryKey(); String entityClass = propertyType.getAssociatedEntityName(); String name = q.createNameFor( entityClass ); q.addType( name, entityClass ); addJoin( name, propertyType ); if ( propertyType.isOneToOne() ) { oneToOneOwnerName = currentName;
/** * Determine the type of either (1) the identifier if we reference the * associated entity's PK or (2) the unique key to which we refer (i.e. * the property-ref). * * @param factory The mappings... * * @return The appropriate type. * * @throws MappingException Generally, if unable to resolve the associated entity name * or unique key property name. */ public final Type getIdentifierOrUniqueKeyType(Mapping factory) throws MappingException { if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) { return getIdentifierType( factory ); } else { Type type = factory.getReferencedPropertyType( getAssociatedEntityName(), uniqueKeyPropertyName ); if ( type.isEntityType() ) { type = ( (EntityType) type ).getIdentifierOrUniqueKeyType( factory ); } return type; } }
@Override public String getOnCondition( String alias, SessionFactoryImplementor factory, Map enabledFilters, Set<String> treatAsDeclarations) { if ( isReferenceToPrimaryKey() && ( treatAsDeclarations == null || treatAsDeclarations.isEmpty() ) ) { return ""; } else { return getAssociatedJoinable( factory ).filterFragment( alias, enabledFilters, treatAsDeclarations ); } }
@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; }
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; } }
/** * 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(); }
/** * 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; } }
Queryable elementPersister = (Queryable) ( (EntityType) elementType ).getAssociatedJoinable( factory ); entityPersisters.add( elementPersister ); entityOwners.add( -1 ); Queryable ownerPersister = determineAppropriateOwnerPersister( ownerDescriptor ); EntityType fetchedType = (EntityType) ownerPersister.getPropertyType( fetchRtn.getOwnerProperty() ); String entityName = fetchedType.getAssociatedEntityName( getFactory() ); Queryable persister = (Queryable) factory.getMetamodel().entityPersister( entityName ); entityPersisters.add( persister ); Queryable elementPersister = (Queryable) ( (EntityType) elementType ).getAssociatedJoinable( factory ); entityPersisters.add( elementPersister ); entityOwners.add( ownerIndex );
protected void initIdentifierPropertyPaths( final String path, final EntityType etype, final String[] columns, final Mapping factory) throws MappingException { Type idtype = etype.getIdentifierOrUniqueKeyType(factory); if ( etype.isReferenceToPrimaryKey() ) { String idpath1 = extendPath(path, EntityPersister.ENTITY_ID); addPropertyPath(idpath1, idtype, columns, null); initPropertyPaths(idpath1, idtype, columns, null, factory); } String idPropName = etype.getIdentifierOrUniqueKeyPropertyName(factory); if (idPropName!=null) { String idpath2 = extendPath(path, idPropName); addPropertyPath(idpath2, idtype, columns, null); initPropertyPaths(idpath2, idtype, columns, null, factory); } }
private void registerNonExists(EntityFetch fetch) { final EntityType fetchedType = fetch.getFetchedType(); if ( ! fetchedType.isOneToOne() ) { return; } final EntityReferenceProcessingState fetchOwnerState = getOwnerProcessingState( fetch ); if ( fetchOwnerState == null ) { throw new IllegalStateException( "Could not locate fetch owner state" ); } final EntityKey ownerEntityKey = fetchOwnerState.getEntityKey(); if ( ownerEntityKey == null ) { throw new IllegalStateException( "Could not locate fetch owner EntityKey" ); } session.getPersistenceContext().addNullProperty( ownerEntityKey, fetchedType.getPropertyName() ); }
if ( entityType.isOneToOne() ) { return value; final String entityName = entityType.getAssociatedEntityName(); return isNullifiable( entityName, value ) ? null : value;
protected final Object getIdentifier(Object value, SharedSessionContractImplementor session) throws HibernateException { if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) { return ForeignKeys.getEntityIdentifierIfNotUnsaved( getAssociatedEntityName(), value, session ); //tolerates nulls } else if ( value == null ) { return null; } else { EntityPersister entityPersister = getAssociatedEntityPersister( session.getFactory() ); Object propertyValue = entityPersister.getPropertyValue( value, uniqueKeyPropertyName ); // We now have the value of the property-ref we reference. However, // we need to dig a little deeper, as that property might also be // an entity type, in which case we need to resolve its identitifier Type type = entityPersister.getPropertyType( uniqueKeyPropertyName ); if ( type.isEntityType() ) { propertyValue = ( (EntityType) type ).getIdentifier( propertyValue, session ); } return propertyValue; } }
AbstractEntityPersister elementPersister = (AbstractEntityPersister) entityPersisters.get(((org.hibernate.type.EntityType) persister.getElementType()).getAssociatedEntityName()); Type identifierType = ((org.hibernate.type.EntityType) persister.getElementType()).getIdentifierOrUniqueKeyType(persister.getFactory()); String identifierOrUniqueKeyPropertyName = ((org.hibernate.type.EntityType) persister.getElementType()).getIdentifierOrUniqueKeyPropertyName(persister.getFactory()); String prefix; if (identifierType instanceof EmbeddedComponentType) {
protected void initIdentifierPropertyPaths( final String path, final EntityType etype, final String[] columns, final String[] columnReaders, final String[] columnReaderTemplates, final Mapping factory) throws MappingException { Type idtype = etype.getIdentifierOrUniqueKeyType( factory ); String idPropName = etype.getIdentifierOrUniqueKeyPropertyName( factory ); boolean hasNonIdentifierPropertyNamedId = hasNonIdentifierPropertyNamedId( etype, factory ); if ( etype.isReferenceToPrimaryKey() ) { if ( !hasNonIdentifierPropertyNamedId ) { String idpath1 = extendPath( path, EntityPersister.ENTITY_ID ); addPropertyPath( idpath1, idtype, columns, columnReaders, columnReaderTemplates, null, factory ); initPropertyPaths( idpath1, idtype, columns, columnReaders, columnReaderTemplates, null, factory ); } } if ( (! etype.isNullable() ) && idPropName != null ) { String idpath2 = extendPath( path, idPropName ); addPropertyPath( idpath2, idtype, columns, columnReaders, columnReaderTemplates, null, factory ); initPropertyPaths( idpath2, idtype, columns, columnReaders, columnReaderTemplates, null, factory ); } }
public final Type getIdentifierOrUniqueKeyType(Mapping factory) throws MappingException { if ( isReferenceToPrimaryKey() ) { return getIdentifierType(factory); } else { return factory.getPropertyType( getAssociatedEntityName(), uniqueKeyPropertyName ); } }
protected final Object getIdentifier(Object value, SessionImplementor session) throws HibernateException { if ( isNotEmbedded(session) ) return value; if ( isReferenceToPrimaryKey() ) { return ForeignKeys.getEntityIdentifierIfNotUnsaved(associatedEntityName, value, session); //tolerates nulls } else if (value==null) { return null; } else { return session.getFactory() .getEntityPersister( getAssociatedEntityName() ) .getPropertyValue( value, uniqueKeyPropertyName, session.getEntityMode() ); } }
if ( singleSubType.isEntityType() ) { final EntityType dependentParentType = (EntityType) singleSubType; final Type dependentParentIdType = dependentParentType.getIdentifierOrUniqueKeyType( event.getSession().getFactory() ); if ( dependentParentIdType.getReturnedClass().isInstance( event.getEntityId() ) ) { persister, dependentIdType, event.getSession().getFactory().getEntityPersister( dependentParentType.getAssociatedEntityName() ) ); return;
/** * Is the association modeled here a 1-1 according to the logical moidel? * * @return True if a 1-1 in the logical model; false otherwise. */ public boolean isLogicalOneToOne() { return isOneToOne(); }
Object id = getIdentifier( original, session ); if ( id == null ) { throw new AssertionFailure( ); id = getIdentifierOrUniqueKeyType( session.getFactory() ) .replace( id, null, session, owner, copyCache ); return resolve( id, session, owner );