Example usage for org.hibernate.mapping Property getValue

List of usage examples for org.hibernate.mapping Property getValue

Introduction

In this page you can find the example usage for org.hibernate.mapping Property getValue.

Prototype

public Value getValue() 

Source Link

Usage

From source file:net.chrisrichardson.ormunit.hibernate.HibernateMappingTests.java

License:Apache License

public CompositeSetFieldMapping getCompositeSetFieldMapping(String fieldName) {
    Property property = classMapping.getProperty(fieldName);
    Value v = property.getValue();
    org.hibernate.mapping.Set value = (org.hibernate.mapping.Set) v;
    return new CompositeSetFieldMapping(property, value);
}

From source file:org.babyfish.hibernate.cfg.Configuration.java

License:Open Source License

private void processPersistentClasses() {
    Iterator<PersistentClass> classMappings = this.getClassMappings();
    while (classMappings.hasNext()) { //TODO: please iterate its subclasses.
        PersistentClass persistentClass = classMappings.next();
        Class<?> mappedClass = persistentClass.getMappedClass();
        ObjectModelFactoryProvider provider = Metadatas.getObjectModelFactoryProvider(mappedClass);
        if (provider == null) {
            if (mappedClass.isAnnotationPresent(JPAObjectModelInstrument.class)) {
                throw new IllegalProgramException(LAZY_RESOURCE.get().missInstrument(mappedClass,
                        JPAObjectModelInstrument.class, INSTRUMENT_EXPECTED_POM_SECTION));
            }//ww w  .jav  a2 s .c  o m
        } else {
            if (!(provider instanceof HibernateObjectModelFactoryProvider)) {
                throw new IllegalProgramException(
                        LAZY_RESOURCE.get().requiredHibernateObjectModelFactoryProvider(mappedClass,
                                HibernateObjectModelFactoryProvider.class));
            }
            HibernateObjectModelMetadata metadata = HibernateMetadatas.of(mappedClass);
            for (org.babyfish.model.metadata.Property property : metadata.getDeclaredProperties().values()) {
                JPAProperty jpaProperty = (JPAProperty) property;
                if (jpaProperty instanceof AssociationProperty) {
                    AssociationProperty associationProperty = (AssociationProperty) jpaProperty;
                    if (associationProperty.getCovarianceProperty() != null) {
                        continue;
                    }
                }
                PropertyInfo ownerProperty = jpaProperty.getOwnerProperty();
                if (ownerProperty == null) {
                    continue;
                }
                Property mappingProperty = persistentClass.getProperty(ownerProperty.getName());
                mappingProperty.setPropertyAccessorName(EntityPropertyAccessor.class.getName());
                Value value = mappingProperty.getValue();
                if (property instanceof AssociationProperty) {
                    JPAAssociationProperty jpaAssociationProperty = (JPAAssociationProperty) property;
                    Class<?> standardReturnType = jpaAssociationProperty.getStandardReturnClass();
                    /*
                     * (1) Don't use jpaAssocationProperty.getHibernateProperty().
                     * This is org.hiberante.mapping.Property, that is org.hibernate.tuple.Property
                     * 
                     * (2) Don't invoke property.getType() or property.getValue().getType()
                     * that will cause the creating of original collection-type before the replacement.
                     */
                    if (jpaAssociationProperty.getCovarianceProperty() == null) {
                        if (standardReturnType == NavigableMap.class) {
                            replaceUserCollectionType(mappingProperty, org.hibernate.mapping.Map.class,
                                    MANavigableMapType.class);
                        } else if (standardReturnType == XOrderedMap.class) {
                            replaceUserCollectionType(mappingProperty, org.hibernate.mapping.Map.class,
                                    MAOrderedMapType.class);
                        } else if (standardReturnType == Map.class) {
                            replaceUserCollectionType(mappingProperty, org.hibernate.mapping.Map.class,
                                    MAOrderedMapType.class);
                        } else if (standardReturnType == NavigableSet.class) {
                            replaceUserCollectionType(mappingProperty, org.hibernate.mapping.Set.class,
                                    MANavigableSetType.class);
                        } else if (standardReturnType == XOrderedSet.class) {
                            replaceUserCollectionType(mappingProperty, org.hibernate.mapping.Set.class,
                                    MAOrderedSetType.class);
                        } else if (standardReturnType == Set.class) {
                            replaceUserCollectionType(mappingProperty, org.hibernate.mapping.Set.class,
                                    MAOrderedSetType.class);
                        } else if (standardReturnType == List.class) {
                            if (org.hibernate.mapping.Bag.class
                                    .isAssignableFrom(mappingProperty.getValue().getClass())) {
                                throw new MappingException(
                                        "In ObjectModel4ORM, Bag proeprty must be declared as java.util.Collection(not java.util.List)");
                            }
                            replaceUserCollectionType(mappingProperty, org.hibernate.mapping.List.class,
                                    MAListType.class);
                        }
                        if (standardReturnType == Collection.class) {
                            replaceUserCollectionType(mappingProperty, org.hibernate.mapping.Bag.class,
                                    MAOrderedSetType.class);
                        }
                        if (value instanceof org.hibernate.mapping.Collection) {
                            org.hibernate.mapping.Collection collection = (org.hibernate.mapping.Collection) value;
                            collection.setTypeParameters(new MACollectionProperties(jpaAssociationProperty,
                                    collection.getTypeParameters()));
                        }

                        if (jpaAssociationProperty.getOwnerIndexProperty() != null) {
                            persistentClass
                                    .getProperty(jpaAssociationProperty.getOwnerIndexProperty().getName())
                                    .setPropertyAccessorName(EntityPropertyAccessor.class.getName());
                        }
                        if (jpaAssociationProperty.getOwnerKeyProperty() != null) {
                            persistentClass.getProperty(jpaAssociationProperty.getOwnerKeyProperty().getName())
                                    .setPropertyAccessorName(EntityPropertyAccessor.class.getName());
                        }
                    }
                }
            }
        }
    }
}

From source file:org.babyfish.hibernate.cfg.Configuration.java

License:Open Source License

private static void replaceUserCollectionType(Property mappingProperty,
        Class<? extends org.hibernate.mapping.Collection> hibernateCollectionType,
        Class<? extends AbstractMACollectionType> babyfishCollectionType) {
    /*//  ww w.ja v  a 2s.  c o m
     * Don't invoke property.getType() or property.getValue().getType()
     * that will cause the creating of original collection-type before the replacement.
     * that is is slow
     */
    Value value = mappingProperty.getValue();
    if (!(value instanceof org.hibernate.mapping.Collection)) {
        throw new MappingException('"' + mappingProperty.getPersistentClass().getEntityName() + '.'
                + mappingProperty.getName() + "\" must be mapped as collection.");
    }
    org.hibernate.mapping.Collection collection = (org.hibernate.mapping.Collection) value;
    String typeName = collection.getTypeName();
    if (typeName == null) {
        if (!hibernateCollectionType.isAssignableFrom(value.getClass())) {
            throw new MappingException('"' + mappingProperty.getPersistentClass().getEntityName() + '.'
                    + mappingProperty.getName() + "\" must be mapped collection whose hibernate type is \""
                    + hibernateCollectionType.getName() + "\".");
        }
        collection.setTypeName(babyfishCollectionType.getName());
    } else {
        Class<?> userCollctionType;
        try {
            userCollctionType = ReflectHelper.classForName(typeName);
        } catch (ClassNotFoundException ex) {
            throw new MappingException(
                    '"' + mappingProperty.getPersistentClass().getEntityName() + '.' + mappingProperty.getName()
                            + "\" must be mapped as collection whose attribute \"collection-type\" is \""
                            + typeName + "\", but the there is no java type names\"" + typeName + "\".");
        }
        if (!babyfishCollectionType.isAssignableFrom(userCollctionType)) {
            throw new MappingException(
                    '"' + mappingProperty.getPersistentClass().getEntityName() + '.' + mappingProperty.getName()
                            + "\" must be mapped as collection whose attribut \"collection-type\" is \""
                            + typeName + "\", but the there class \"" + typeName + "\" is not \""
                            + babyfishCollectionType.getName() + "\" or its derived class.");
        }
    }
}

From source file:org.beangle.orm.hibernate.tool.DdlGenerator.java

License:Open Source License

/**
 * get component class by component property string
 * /*  www .ja  v  a 2 s  .c om*/
 * @param pc
 * @param propertyString
 * @return
 */
private Class<?> getPropertyType(PersistentClass pc, String propertyString) {
    String[] properties = split(propertyString, '.');
    Property p = pc.getProperty(properties[0]);
    Component cp = ((Component) p.getValue());
    int i = 1;
    for (; i < properties.length; i++) {
        p = cp.getProperty(properties[i]);
        cp = ((Component) p.getValue());
    }
    return cp.getComponentClass();
}

From source file:org.beangle.orm.hibernate.tool.DdlGenerator.java

License:Open Source License

@SuppressWarnings("unchecked")
private void commentProperty(Class<?> clazz, Table table, Property p) {
    if (null == p)
        return;//from  w  ww.ja v  a2  s  .co  m
    if (p.getColumnSpan() == 1) {
        Column column = (Column) p.getColumnIterator().next();
        if (isForeignColumn(table, column)) {
            column.setComment(messages.get(clazz, p.getName()) + " ID");
        } else {
            column.setComment(messages.get(clazz, p.getName()));
        }
    } else if (p.getColumnSpan() > 1) {
        Component pc = ((Component) p.getValue());
        Class<?> columnOwnerClass = pc.getComponentClass();
        commentProperties(columnOwnerClass, table, pc.getPropertyIterator());
    }
}

From source file:org.broadleafcommerce.openadmin.server.dao.DynamicEntityDaoImpl.java

License:Apache License

protected void buildComponentProperties(Class<?> targetClass, ForeignKey foreignField,
        ForeignKey[] additionalForeignFields, String[] additionalNonPersistentProperties,
        MergedPropertyType mergedPropertyType, Map<String, FieldMetadata> fields, String idProperty,
        Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields,
        String configurationKey, String ceilingEntityFullyQualifiedClassname, String propertyName, Type type,
        Class<?> returnedClass, List<Class<?>> parentClasses, Boolean isParentExcluded, String prefix)
        throws MappingException, HibernateException, ClassNotFoundException, SecurityException,
        IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    String[] componentProperties = ((ComponentType) type).getPropertyNames();
    List<String> componentPropertyNames = Arrays.asList(componentProperties);
    Type[] componentTypes = ((ComponentType) type).getSubtypes();
    List<Type> componentPropertyTypes = Arrays.asList(componentTypes);
    Map<String, FieldPresentationAttributes> componentPresentationAttributes = getFieldPresentationAttributes(
            returnedClass);//from ww w.jav  a2  s  .c om
    if (isParentExcluded) {
        for (String key : componentPresentationAttributes.keySet()) {
            componentPresentationAttributes.get(key).setExcluded(true);
        }
    }
    PersistentClass persistentClass = getPersistentClass(targetClass.getName());
    Property property;
    try {
        property = persistentClass.getProperty(propertyName);
    } catch (MappingException e) {
        property = persistentClass.getProperty(prefix + propertyName);
    }
    @SuppressWarnings("unchecked")
    Iterator<Property> componentPropertyIterator = ((Component) property.getValue()).getPropertyIterator();
    List<Property> componentPropertyList = new ArrayList<Property>();
    while (componentPropertyIterator.hasNext()) {
        componentPropertyList.add(componentPropertyIterator.next());
    }
    Map<String, FieldMetadata> newFields = new HashMap<String, FieldMetadata>();
    buildProperties(targetClass, foreignField, additionalForeignFields, additionalNonPersistentProperties,
            mergedPropertyType, componentPresentationAttributes, componentPropertyList, newFields,
            componentPropertyNames, componentPropertyTypes, idProperty, populateManyToOneFields, includeFields,
            excludeFields, configurationKey, ceilingEntityFullyQualifiedClassname, parentClasses,
            propertyName + ".", isParentExcluded);
    Map<String, FieldMetadata> convertedFields = new HashMap<String, FieldMetadata>();
    for (String key : newFields.keySet()) {
        convertedFields.put(propertyName + "." + key, newFields.get(key));
    }
    fields.putAll(convertedFields);
}

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

protected boolean isBidirectionalManyToOneWithListMapping(GrailsDomainClassProperty grailsProperty,
        Property prop) {
    GrailsDomainClassProperty otherSide = grailsProperty.getOtherSide();
    return grailsProperty.isBidirectional() && otherSide != null && prop.getValue() instanceof ManyToOne
            && List.class.isAssignableFrom(otherSide.getType());
}

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

private static boolean isBidirectionalManyToOneWithListMapping(GrailsDomainClassProperty grailsProperty,
        Property prop) {
    GrailsDomainClassProperty otherSide = grailsProperty.getOtherSide();
    return grailsProperty.isBidirectional() && otherSide != null && prop.getValue() instanceof ManyToOne
            && List.class.isAssignableFrom(otherSide.getType());
}

From source file:org.compass.gps.device.hibernate.embedded.CompassEventListener.java

License:Apache License

private CompassHolder initCompassHolder(Configuration cfg) {
    Properties compassProperties = new Properties();
    //noinspection unchecked
    Properties props = cfg.getProperties();
    for (Map.Entry entry : props.entrySet()) {
        String key = (String) entry.getKey();
        if (key.startsWith(COMPASS_PREFIX)) {
            compassProperties.put(entry.getKey(), entry.getValue());
        }//  w w  w .  j  a va  2  s.co  m
        if (key.startsWith(COMPASS_GPS_INDEX_PREFIX)) {
            compassProperties.put(entry.getKey(), entry.getValue());
        }
    }
    if (compassProperties.isEmpty()) {
        if (log.isDebugEnabled()) {
            log.debug("No Compass properties defined, disabling Compass");
        }
        return null;
    }
    if (compassProperties.getProperty(CompassEnvironment.CONNECTION) == null) {
        if (log.isDebugEnabled()) {
            log.debug("No Compass [" + CompassEnvironment.CONNECTION + "] property defined, disabling Compass");
        }
        return null;
    }

    processCollections = compassProperties.getProperty(COMPASS_PROCESS_COLLECTIONS, "true")
            .equalsIgnoreCase("true");

    CompassConfiguration compassConfiguration = CompassConfigurationFactory.newConfiguration();
    CompassSettings settings = compassConfiguration.getSettings();
    settings.addSettings(compassProperties);

    String configLocation = (String) compassProperties.get(COMPASS_CONFIG_LOCATION);
    if (configLocation != null) {
        compassConfiguration.configure(configLocation);
    }

    boolean atleastOneClassAdded = false;
    for (Iterator it = cfg.getClassMappings(); it.hasNext();) {
        PersistentClass clazz = (PersistentClass) it.next();
        Class<?> mappedClass = clazz.getMappedClass();
        for (Iterator propIt = clazz.getPropertyIterator(); propIt.hasNext();) {
            Property prop = (Property) propIt.next();
            Value value = prop.getValue();
            if (value instanceof Component) {
                Component component = (Component) value;
                try {
                    atleastOneClassAdded |= compassConfiguration.tryAddClass(
                            ClassUtils.forName(component.getComponentClassName(), settings.getClassLoader()));
                } catch (ClassNotFoundException e) {
                    log.warn("Failed to load component class [" + component.getComponentClassName() + "]", e);
                }
            }
        }
        Value idValue = clazz.getIdentifierProperty().getValue();
        if (idValue instanceof Component) {
            Component component = (Component) idValue;
            try {
                atleastOneClassAdded |= compassConfiguration.tryAddClass(
                        ClassUtils.forName(component.getComponentClassName(), settings.getClassLoader()));
            } catch (ClassNotFoundException e) {
                log.warn("Failed to load component class [" + component.getComponentClassName() + "]", e);
            }
        }
        atleastOneClassAdded |= compassConfiguration.tryAddClass(mappedClass);
    }
    if (!atleastOneClassAdded) {
        if (log.isDebugEnabled()) {
            log.debug("No searchable class mappings found in Hibernate class mappings, disabling Compass");
        }
        return null;
    }

    CompassHolder compassHolder = new CompassHolder();
    compassHolder.compassProperties = compassProperties;

    compassHolder.commitBeforeCompletion = settings
            .getSettingAsBoolean(CompassEnvironment.Transaction.COMMIT_BEFORE_COMPLETION, false);

    String transactionFactory = (String) compassProperties.get(CompassEnvironment.Transaction.FACTORY);
    if (transactionFactory == null) {
        String hibernateTransactionStrategy = cfg.getProperty(Environment.TRANSACTION_STRATEGY);
        if (CMTTransactionFactory.class.getName().equals(hibernateTransactionStrategy)
                || JTATransactionFactory.class.getName().equals(hibernateTransactionStrategy)) {
            // hibernate is configured with JTA, automatically configure Compass to use its JTASync (by default)
            compassHolder.hibernateControlledTransaction = false;
            compassConfiguration.setSetting(CompassEnvironment.Transaction.FACTORY,
                    JTASyncTransactionFactory.class.getName());
        } else {
            // Hibernate JDBC transaction manager, let Compass use the local transaction manager
            compassHolder.hibernateControlledTransaction = true;
            // if the settings is configured to use local transaciton, disable thread bound setting since
            // we are using Hibernate to managed transaction scope (using the transaction to holder map) and not thread locals
            if (settings
                    .getSetting(CompassEnvironment.Transaction.DISABLE_THREAD_BOUND_LOCAL_TRANSATION) == null) {
                settings.setBooleanSetting(CompassEnvironment.Transaction.DISABLE_THREAD_BOUND_LOCAL_TRANSATION,
                        true);
            }
        }
    } else if (LocalTransactionFactory.class.getName().equals(transactionFactory)) {
        compassHolder.hibernateControlledTransaction = true;
        // if the settings is configured to use local transaciton, disable thread bound setting since
        // we are using Hibernate to managed transaction scope (using the transaction to holder map) and not thread locals
        if (settings.getSetting(CompassEnvironment.Transaction.DISABLE_THREAD_BOUND_LOCAL_TRANSATION) == null) {
            settings.setBooleanSetting(CompassEnvironment.Transaction.DISABLE_THREAD_BOUND_LOCAL_TRANSATION,
                    true);
        }
    } else {
        // Hibernate is not controlling the transaction (using JTA Sync or XA), don't commit/rollback
        // with Hibernate transaction listeners
        compassHolder.hibernateControlledTransaction = false;
    }

    compassHolder.indexSettings = new Properties();
    for (Map.Entry entry : compassProperties.entrySet()) {
        String key = (String) entry.getKey();
        if (key.startsWith(COMPASS_GPS_INDEX_PREFIX)) {
            compassHolder.indexSettings.put(key.substring(COMPASS_GPS_INDEX_PREFIX.length()), entry.getValue());
        }
    }

    String mirrorFilterClass = compassHolder.compassProperties.getProperty(COMPASS_MIRROR_FILTER);
    if (mirrorFilterClass != null) {
        try {
            compassHolder.mirrorFilter = (HibernateMirrorFilter) ClassUtils
                    .forName(mirrorFilterClass, compassConfiguration.getSettings().getClassLoader())
                    .newInstance();
        } catch (Exception e) {
            throw new CompassException("Failed to create mirror filter [" + mirrorFilterClass + "]", e);
        }
    }

    compassHolder.compass = compassConfiguration.buildCompass();

    return compassHolder;
}

From source file:org.eclipse.emf.teneo.hibernate.HbDataStore.java

License:Open Source License

/**
 * Extra lazy mapping for lists needs a real property for the list index and
 * a real inverse for the other side as well.
 * /*  ww w .java  2 s  .  c om*/
 * This method iterates over all associations and adds an inverse for the
 * list and set mappings.
 */
protected void addExtraLazyInverseProperties() {
    final Map<String, PersistentClass> persistentClasses = new HashMap<String, PersistentClass>();
    for (Iterator<?> pcs = getClassMappings(); pcs.hasNext();) {
        final PersistentClass pc = (PersistentClass) pcs.next();
        if (isClassOrSuperClassEAVMapped(pc)) {
            continue;
        }
        persistentClasses.put(pc.getEntityName(), pc);
    }
    for (Iterator<?> pcs = getClassMappings(); pcs.hasNext();) {
        final PersistentClass pc = (PersistentClass) pcs.next();

        // copy to prevent concurrent modification
        final Iterator<?> propIt = pc.getPropertyIterator();
        final List<Property> props = new ArrayList<Property>();
        while (propIt.hasNext()) {
            final Property prop = (Property) propIt.next();
            props.add(prop);
        }

        for (Property prop : props) {
            EClass eClass = null;
            if (pc.getMetaAttribute(HbMapperConstants.FEATUREMAP_META) == null) {
                if (pc.getEntityName() != null) {
                    eClass = getEntityNameStrategy().toEClass(pc.getEntityName());
                } else {
                    eClass = EModelResolver.instance().getEClass(pc.getMappedClass());
                }
            }

            final EStructuralFeature ef = eClass == null ? null
                    : StoreUtil.getEStructuralFeature(eClass, prop.getName());
            if (ef != null && ef instanceof EReference && prop.getValue() instanceof Collection) {
                final Collection collection = (Collection) prop.getValue();
                final EReference eReference = (EReference) ef;

                // only work for extra lazy
                if (!collection.isExtraLazy()) {
                    continue;
                }

                final Value elementValue = collection.getElement();
                final PersistentClass elementPC;
                if (elementValue instanceof OneToMany) {
                    final OneToMany oneToMany = (OneToMany) elementValue;
                    elementPC = oneToMany.getAssociatedClass();
                } else if (elementValue instanceof ManyToOne) {
                    final ManyToOne mto = (ManyToOne) elementValue;
                    elementPC = persistentClasses.get(mto.getReferencedEntityName());
                } else {
                    continue;
                }

                if (isClassOrSuperClassEAVMapped(elementPC)) {
                    continue;
                }

                collection.setInverse(true);

                // and add an eopposite
                if (eReference.getEOpposite() == null) {

                    final Table collectionTable = collection.getCollectionTable();

                    if (isClassOrSuperClassEAVMapped(elementPC)) {
                        continue;
                    }

                    final Property inverseRefProperty = new Property();
                    inverseRefProperty.setName(StoreUtil.getExtraLazyInversePropertyName(ef));
                    final Map<Object, Object> metas = new HashMap<Object, Object>();
                    final MetaAttribute metaAttribute = new MetaAttribute(
                            HbConstants.SYNTHETIC_PROPERTY_INDICATOR);
                    metaAttribute.addValue("true");
                    metas.put(HbConstants.SYNTHETIC_PROPERTY_INDICATOR, metaAttribute);
                    inverseRefProperty.setMetaAttributes(metas);
                    inverseRefProperty.setNodeName(inverseRefProperty.getName());
                    inverseRefProperty.setPropertyAccessorName(SyntheticPropertyHandler.class.getName());
                    inverseRefProperty.setLazy(false);

                    final ManyToOne mto = new ManyToOne(getMappings(), collectionTable);
                    mto.setReferencedEntityName(pc.getEntityName());
                    mto.setLazy(false);
                    mto.setFetchMode(FetchMode.SELECT);

                    inverseRefProperty.setValue(mto);
                    final Iterator<?> it = collection.getKey().getColumnIterator();
                    while (it.hasNext()) {
                        final Column originalColumn = (Column) it.next();
                        // final Column newColumn = new
                        // Column(originalColumn.getName());
                        mto.addColumn(originalColumn);
                    }
                    mto.createForeignKey();

                    // now determine if a join should be created
                    if (collectionTable.getName().equalsIgnoreCase(elementPC.getTable().getName())) {
                        elementPC.addProperty(inverseRefProperty);
                    } else {
                        // create a join
                        final Join join = new Join();
                        join.setPersistentClass(elementPC);
                        join.setTable(collectionTable);
                        join.addProperty(inverseRefProperty);

                        final ManyToOne keyValue = new ManyToOne(getMappings(), collectionTable);
                        join.setKey(keyValue);
                        @SuppressWarnings("unchecked")
                        final Iterator<Column> keyColumns = collection.getElement().getColumnIterator();
                        while (keyColumns.hasNext()) {
                            keyValue.addColumn(keyColumns.next());
                        }
                        keyValue.setReferencedEntityName(elementPC.getEntityName());
                        keyValue.setTable(collectionTable);
                        keyValue.createForeignKey();

                        elementPC.addJoin(join);
                    }
                }

                // add an opposite index
                if (collection.isIndexed() && !collection.isMap()) {

                    Table collectionTable = collection.getCollectionTable();

                    IndexedCollection indexedCollection = (IndexedCollection) collection;

                    final Column column = (Column) indexedCollection.getIndex().getColumnIterator().next();

                    final Property indexProperty = new Property();
                    indexProperty.setName(StoreUtil.getExtraLazyInverseIndexPropertyName(ef));
                    final Map<Object, Object> metas = new HashMap<Object, Object>();
                    final MetaAttribute metaAttribute = new MetaAttribute(
                            HbConstants.SYNTHETIC_PROPERTY_INDICATOR);
                    metaAttribute.addValue("true");
                    metas.put(HbConstants.SYNTHETIC_PROPERTY_INDICATOR, metaAttribute);
                    indexProperty.setMetaAttributes(metas);
                    indexProperty.setNodeName(indexProperty.getName());
                    indexProperty.setPropertyAccessorName(SyntheticPropertyHandler.class.getName());
                    // always make this nullable, nullability is controlled
                    // by the main property
                    indexProperty.setOptional(true);

                    Join join = null;
                    @SuppressWarnings("unchecked")
                    final Iterator<Join> it = (Iterator<Join>) elementPC.getJoinIterator();
                    while (it.hasNext()) {
                        final Join foundJoin = it.next();
                        if (foundJoin.getTable().getName().equalsIgnoreCase(collectionTable.getName())) {
                            join = foundJoin;
                            collectionTable = join.getTable();
                            break;
                        }
                    }

                    final SimpleValue sv = new SimpleValue(getMappings(),
                            indexedCollection.getIndex().getTable());
                    sv.setTypeName("integer");
                    // final Column svColumn = new Column(column.getName());
                    sv.addColumn(column); // checkColumnExists(collectionTable,
                    // svColumn));
                    indexProperty.setValue(sv);
                    if (join != null) {
                        join.addProperty(indexProperty);
                    } else {
                        elementPC.addProperty(indexProperty);
                    }
                }
            }
        }
    }

}