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; } }
); id = getIdentifierOrUniqueKeyType( session.getFactory() ) .replace( id, null, session, owner, copyCache ); return resolve( id, session, owner );
/** * 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; } }
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 ); } }
if ( singleSubType.isEntityType() ) { final EntityType dependentParentType = (EntityType) singleSubType; final Type dependentParentIdType = dependentParentType.getIdentifierOrUniqueKeyType( event.getSession().getFactory() ); if ( dependentParentIdType.getReturnedClass().isInstance( event.getEntityId() ) ) {
uniqueKeyPropertyName, key, getIdentifierOrUniqueKeyType( factory ), persister.getEntityMode(), session.getFactory()
private GridType getIdGridType(SessionFactoryImplementor sessionFactory) { final Type idType = delegate.getIdentifierOrUniqueKeyType( sessionFactory ); GridType idGridType = typeTranslator.getType( idType ); return idGridType; }
private String[] getColumnTypeForPropertyType(EntityType<?> entityType, String attributeName, SessionFactoryImplementor sfi, Type propertyType) { if (propertyType instanceof org.hibernate.type.EntityType) { propertyType = ((org.hibernate.type.EntityType) propertyType).getIdentifierOrUniqueKeyType(sfi); } long length = Column.DEFAULT_LENGTH; int precision = Column.DEFAULT_PRECISION; int scale = Column.DEFAULT_SCALE; try { Method m = Type.class.getMethod("dictatedSizes", Mapping.class); Object size = ((Object[]) m.invoke(propertyType, sfi))[0]; length = (long) size.getClass().getMethod("getLength").invoke(size); precision = (int) size.getClass().getMethod("getPrecision").invoke(size); scale = (int) size.getClass().getMethod("getScale").invoke(size); } catch (Exception ex) { LOG.fine("Could not determine the column type of the attribute: " + attributeName + " of the entity: " + entityType.getName()); } return new String[] { sfi.getDialect().getTypeName( propertyType.sqlTypes(sfi)[0], length, precision, scale ) }; }
public Object replace(Object original, Object target, SessionImplementor session, Object owner, Map copyCache) throws HibernateException { if (original==null) return null; Object cached = copyCache.get(original); if (cached!=null) { return cached; } else { if (original==target) return target; //TODO: can this ever get called???? Object id = getIdentifier(original, session); if (id==null) throw new AssertionFailure("cannot copy a reference to an object with a null id"); id = getIdentifierOrUniqueKeyType( session.getFactory() ).replace(id, null, session, owner, copyCache); return resolve(id, session, owner); } }
private void collectPropertyNames(Collection<String> propertyNames, String prefix, Type propertyType, Mapping factory) { if (propertyType instanceof ComponentType) { ComponentType componentType = (ComponentType) propertyType; for (String propertyName : componentType.getPropertyNames()) { Type subtype = componentType.getSubtypes()[componentType.getPropertyIndex(propertyName)]; collectPropertyNames(propertyNames, prefix == null ? propertyName : prefix + "." + propertyName, subtype, factory); } } else if (propertyType instanceof org.hibernate.type.EntityType) { org.hibernate.type.EntityType entityType = (org.hibernate.type.EntityType) propertyType; Type identifierOrUniqueKeyType = entityType.getIdentifierOrUniqueKeyType(factory); if (identifierOrUniqueKeyType instanceof EmbeddedComponentType) { EmbeddedComponentType embeddedComponentType = (EmbeddedComponentType) identifierOrUniqueKeyType; for (String propertyName : embeddedComponentType.getPropertyNames()) { propertyNames.add(prefix == null ? propertyName : prefix + "." + propertyName); } } else { String identifierOrUniqueKeyPropertyName = entityType.getIdentifierOrUniqueKeyPropertyName(factory); propertyNames.add(prefix == null ? identifierOrUniqueKeyPropertyName : prefix + "." + identifierOrUniqueKeyPropertyName); } } else if (!(propertyType instanceof CollectionType) && prefix != null) { propertyNames.add(prefix); } }
/** * 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() ) { return getIdentifierType(factory); } else { Type type = factory.getReferencedPropertyType( getAssociatedEntityName(), uniqueKeyPropertyName ); if ( type.isEntityType() ) { type = ( ( EntityType ) type).getIdentifierOrUniqueKeyType( factory ); } return type; } }
/** * 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() ) { return getIdentifierType(factory); } else { Type type = factory.getReferencedPropertyType( getAssociatedEntityName(), uniqueKeyPropertyName ); if ( type.isEntityType() ) { type = ( ( EntityType ) type).getIdentifierOrUniqueKeyType( factory ); } return type; } }
throw new AssertionFailure("non-transient entity has a null id"); id = getIdentifierOrUniqueKeyType( session.getFactory() ) .replace(id, null, session, owner, copyCache); return resolve( id, session, owner );
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); } }
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); } }
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); initPropertyPaths(idpath1, idtype, columns, columnReaders, columnReaderTemplates, null, factory); } } if (idPropName!=null) { String idpath2 = extendPath(path, idPropName); addPropertyPath(idpath2, idtype, columns, columnReaders, columnReaderTemplates, null); initPropertyPaths(idpath2, idtype, columns, columnReaders, columnReaderTemplates, null, factory); } }
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); initPropertyPaths(idpath1, idtype, columns, columnReaders, columnReaderTemplates, null, factory); } } if (idPropName!=null) { String idpath2 = extendPath(path, idPropName); addPropertyPath(idpath2, idtype, columns, columnReaders, columnReaderTemplates, null); initPropertyPaths(idpath2, idtype, columns, columnReaders, columnReaderTemplates, null, factory); } }
uniqueKeyPropertyName, key, getIdentifierOrUniqueKeyType( factory ), session.getEntityMode(), session.getFactory()
uniqueKeyPropertyName, key, getIdentifierOrUniqueKeyType( factory ), persister.getEntityMode(), session.getFactory()
uniqueKeyPropertyName, key, getIdentifierOrUniqueKeyType( factory ), persister.getEntityMode(), session.getFactory()