Example usage for org.hibernate.mapping Component Component

List of usage examples for org.hibernate.mapping Component Component

Introduction

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

Prototype

public Component(MetadataBuildingContext metadata, Collection collection) throws MappingException 

Source Link

Usage

From source file:com.javaetmoi.core.persistence.hibernate.TestReflectionUtil.java

License:Apache License

@Before
public void setUp() {
    Configuration configuration = new Configuration();
    Mappings mappings = configuration.createMappings();
    Component component = new Component(mappings, new RootClass());
    Property p1 = new Property();
    p1.setName("client");
    SimpleValue p1val = new SimpleValue(mappings);
    p1val.setTypeName("java.lang.Integer");
    p1.setValue(p1val);
    component.addProperty(p1);//from w w  w  .jav  a 2 s  .c o m
    Property p2 = new Property();
    p2.setName("user");
    SimpleValue p2val = new SimpleValue(mappings);
    p2val.setTypeName("java.lang.String");
    p2.setValue(p2val);
    component.addProperty(p2);
    metadata = new ComponentMetamodel(component);
}

From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java

License:Open Source License

protected void createPKComposite(Mappings mappings, com.manydesigns.portofino.model.database.Table mdTable,
        String pkName, RootClass clazz, Table tab,
        List<com.manydesigns.portofino.model.database.Column> columnPKList) {

    PrimaryKey primaryKey = new PrimaryKey();
    primaryKey.setName(pkName);//from   w ww. j a  va  2  s  .  c om
    primaryKey.setTable(tab);

    clazz.setEmbeddedIdentifier(true);
    Component component = new Component(mappings, clazz);
    component.setDynamic(mdTable.getActualJavaClass() == null);
    String name;
    name = mdTable.getQualifiedName();

    component.setRoleName(name + ".id");
    component.setEmbedded(true);
    //component.setNodeName("id");
    component.setKey(true);
    component.setNullValue("undefined");

    if (!component.isDynamic()) {
        component.setComponentClassName(mdTable.getJavaClass()); //TODO verificare se non si intende actualJavaClass
    }

    boolean hasErrors = false;
    for (com.manydesigns.portofino.model.database.Column column : columnPKList) {
        if (column == null) {
            throw new InternalError("Null column");
        }

        Column col = createColumn(mappings, tab, column);

        hasErrors = col == null || hasErrors;

        if (col != null) {
            primaryKey.addColumn(col);
            Property prop = createProperty(column, col.getValue());
            prop.setCascade("none");
            //prop.setPropertyAccessorName("property"); interferisce con il generator pi sotto
            prop.setPersistentClass(clazz);
            component.addProperty(prop);

            //Generator not supported for embedded map identifier
            //See https://forum.hibernate.org/viewtopic.php?t=945273
            //See Component.buildIdentifierGenerator()
            /*String columnName = column.getColumnName();
            PrimaryKeyColumn pkCol = mdTable.getPrimaryKey().findPrimaryKeyColumnByName(columnName);
            if(pkCol == null) {
            logger.error("Column without corresponding PrimaryKeyColumn: {}", columnName);
            hasErrors = true;
            continue;
            }
            Generator generator = pkCol.getGenerator();
            setPKColumnGenerator(mappings, clazz, tab, column, value, generator);*/
        }
    }
    if (hasErrors) {
        // TODO PAOLO: se la PK non e' buona, tutta la tabella dovrebbe saltare
        logger.error("Skipping primary key");
        return;
    }

    tab.setIdentifierValue(component);
    clazz.setIdentifier(component);
    clazz.setDiscriminatorValue(name);

    tab.setPrimaryKey(primaryKey);
}

From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java

License:Open Source License

private DependantValue createFKComposite(Mappings mappings,
        com.manydesigns.portofino.model.database.ForeignKey relationship,
        com.manydesigns.portofino.model.database.Table manyMDTable, PersistentClass clazzOne,
        PersistentClass clazzMany, Bag set, Table tableMany, Table tableOne, List<Column> oneColumns,
        List<Column> manyColumns) {
    DependantValue dv;/*from  w ww .j  a v a 2  s.c  o  m*/
    Component component = new Component(mappings, set);
    component.setDynamic(manyMDTable.getActualJavaClass() == null);
    component.setEmbedded(true);
    dv = new DependantValue(mappings, clazzMany.getTable(), component);
    dv.setNullable(true);
    dv.setUpdateable(true);

    for (Reference ref : relationship.getReferences()) {
        String colToName = ref.getToColumn();
        String colToPropertyName = ref.getActualToColumn().getActualPropertyName();
        String colFromName = ref.getFromColumn();
        Iterator it = tableMany.getColumnIterator();
        while (it.hasNext()) {
            Column col = (Column) it.next();
            if (col.getName().equals(colFromName)) {
                dv.addColumn(col);
                manyColumns.add(col);
                break;
            }
        }

        Iterator it2 = tableOne.getColumnIterator();
        while (it2.hasNext()) {
            Column col = (Column) it2.next();
            if (col.getName().equals(colToName)) {
                oneColumns.add(col);
                break;
            }
        }
        Property refProp;
        refProp = getRefProperty(clazzOne, colToPropertyName);
        component.addProperty(refProp);
    }
    return dv;
}

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

License:Apache License

protected void bindCompositeId(GrailsDomainClass domainClass, RootClass root,
        CompositeIdentity compositeIdentity, Mappings mappings, String sessionFactoryBeanName) {
    Component id = new Component(mappings, root);
    id.setNullValue("undefined");
    root.setIdentifier(id);//from  ww  w  . j  a v a  2 s .co  m
    root.setEmbeddedIdentifier(true);
    id.setComponentClassName(domainClass.getFullName());
    id.setKey(true);
    id.setEmbedded(true);

    String path = qualify(root.getEntityName(), "id");

    id.setRoleName(path);

    String[] props = compositeIdentity.getPropertyNames();
    for (String propName : props) {
        GrailsDomainClassProperty property = domainClass.getPropertyByName(propName);
        if (property == null) {
            throw new MappingException(
                    "Property [" + propName + "] referenced in composite-id mapping of class ["
                            + domainClass.getFullName() + "] is not a valid property!");
        }

        bindComponentProperty(id, null, property, root, "", root.getTable(), mappings, sessionFactoryBeanName);
    }
}

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

License:Apache License

/**
 * Creates and binds the properties for the specified Grails domain class and PersistentClass
 * and binds them to the Hibernate runtime meta model
 *
 * @param domainClass     The Grails domain class
 * @param persistentClass The Hibernate PersistentClass instance
 * @param mappings        The Hibernate Mappings instance
 * @param sessionFactoryBeanName  the session factory bean name
 *//* w  ww.ja  va2s . c o  m*/
protected void createClassProperties(GrailsDomainClass domainClass, PersistentClass persistentClass,
        Mappings mappings, String sessionFactoryBeanName) {

    GrailsDomainClassProperty[] persistentProperties = domainClass.getPersistentProperties();
    Table table = persistentClass.getTable();

    Mapping gormMapping = getMapping(domainClass.getClazz());

    if (gormMapping != null) {
        table.setComment(gormMapping.getComment());
    }

    for (GrailsDomainClassProperty currentGrailsProp : persistentProperties) {

        // if its inherited skip
        boolean isBidirectionalManyToOne = isBidirectionalManyToOne(currentGrailsProp);
        if (currentGrailsProp.isInherited()) {
            continue;
        }
        if (currentGrailsProp.isInherited() && isBidirectionalManyToOne && currentGrailsProp.isCircular()) {
            continue;
        }
        if (isCompositeIdProperty(gormMapping, currentGrailsProp))
            continue;
        if (isIdentityProperty(gormMapping, currentGrailsProp))
            continue;

        if (LOG.isDebugEnabled()) {
            LOG.debug("[GrailsDomainBinder] Binding persistent property [" + currentGrailsProp.getName() + "]");
        }

        Value value = null;

        // see if it's a collection type
        CollectionType collectionType = CT.collectionTypeForClass(currentGrailsProp.getType());

        Class<?> userType = getUserType(currentGrailsProp);

        if (userType != null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName()
                        + "] as SimpleValue");
            }
            value = new SimpleValue(mappings, table);
            bindSimpleValue(currentGrailsProp, null, (SimpleValue) value, EMPTY_PATH, mappings,
                    sessionFactoryBeanName);
        } else if (collectionType != null) {
            String typeName = getTypeName(currentGrailsProp, getPropertyConfig(currentGrailsProp), gormMapping);
            if ("serializable".equals(typeName)) {
                value = new SimpleValue(mappings, table);
                bindSimpleValue(typeName, (SimpleValue) value, currentGrailsProp.isOptional(),
                        getColumnNameForPropertyAndPath(currentGrailsProp, EMPTY_PATH, null,
                                sessionFactoryBeanName),
                        mappings);
            } else {
                // create collection
                Collection collection = collectionType.create(currentGrailsProp, persistentClass, EMPTY_PATH,
                        mappings, sessionFactoryBeanName);
                mappings.addCollection(collection);
                value = collection;
            }
        } else if (currentGrailsProp.isEnum()) {
            value = new SimpleValue(mappings, table);
            bindEnumType(currentGrailsProp, (SimpleValue) value, EMPTY_PATH, sessionFactoryBeanName);
        }
        // work out what type of relationship it is and bind value
        else if (currentGrailsProp.isManyToOne()) {
            if (LOG.isDebugEnabled())
                LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName()
                        + "] as ManyToOne");

            value = new ManyToOne(mappings, table);
            bindManyToOne(currentGrailsProp, (ManyToOne) value, EMPTY_PATH, mappings, sessionFactoryBeanName);
        } else if (currentGrailsProp.isOneToOne() && userType == null) {
            if (LOG.isDebugEnabled())
                LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName()
                        + "] as OneToOne");

            if (currentGrailsProp.isHasOne() && !currentGrailsProp.isBidirectional()) {
                throw new MappingException("hasOne property [" + currentGrailsProp.getDomainClass().getName()
                        + "." + currentGrailsProp.getName()
                        + "] is not bidirectional. Specify the other side of the relationship!");
            } else if (canBindOneToOneWithSingleColumnAndForeignKey(currentGrailsProp)) {
                value = new OneToOne(mappings, table, persistentClass);
                bindOneToOne(currentGrailsProp, (OneToOne) value, EMPTY_PATH, sessionFactoryBeanName);
            } else {
                if (currentGrailsProp.isHasOne() && currentGrailsProp.isBidirectional()) {
                    value = new OneToOne(mappings, table, persistentClass);
                    bindOneToOne(currentGrailsProp, (OneToOne) value, EMPTY_PATH, sessionFactoryBeanName);
                } else {
                    value = new ManyToOne(mappings, table);
                    bindManyToOne(currentGrailsProp, (ManyToOne) value, EMPTY_PATH, mappings,
                            sessionFactoryBeanName);
                }
            }
        } else if (currentGrailsProp.isEmbedded()) {
            value = new Component(mappings, persistentClass);

            bindComponent((Component) value, currentGrailsProp, true, mappings, sessionFactoryBeanName);
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName()
                        + "] as SimpleValue");
            }
            value = new SimpleValue(mappings, table);
            bindSimpleValue(currentGrailsProp, null, (SimpleValue) value, EMPTY_PATH, mappings,
                    sessionFactoryBeanName);
        }

        if (value != null) {
            Property property = createProperty(value, persistentClass, currentGrailsProp, mappings);
            persistentClass.addProperty(property);
        }
    }

    bindNaturalIdentifier(table, gormMapping, persistentClass);
}

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

License:Apache License

protected void bindComponentProperty(Component component, GrailsDomainClassProperty componentProperty,
        GrailsDomainClassProperty currentGrailsProp, PersistentClass persistentClass, String path, Table table,
        Mappings mappings, String sessionFactoryBeanName) {
    Value value;//from  ww w .j av  a 2  s  .  c om
    // see if it's a collection type
    CollectionType collectionType = CT.collectionTypeForClass(currentGrailsProp.getType());
    if (collectionType != null) {
        // create collection
        Collection collection = collectionType.create(currentGrailsProp, persistentClass, path, mappings,
                sessionFactoryBeanName);
        mappings.addCollection(collection);
        value = collection;
    }
    // work out what type of relationship it is and bind value
    else if (currentGrailsProp.isManyToOne()) {
        if (LOG.isDebugEnabled())
            LOG.debug(
                    "[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as ManyToOne");

        value = new ManyToOne(mappings, table);
        bindManyToOne(currentGrailsProp, (ManyToOne) value, path, mappings, sessionFactoryBeanName);
    } else if (currentGrailsProp.isOneToOne()) {
        if (LOG.isDebugEnabled())
            LOG.debug(
                    "[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as OneToOne");

        if (canBindOneToOneWithSingleColumnAndForeignKey(currentGrailsProp)) {
            value = new OneToOne(mappings, table, persistentClass);
            bindOneToOne(currentGrailsProp, (OneToOne) value, path, sessionFactoryBeanName);
        } else {
            value = new ManyToOne(mappings, table);
            bindManyToOne(currentGrailsProp, (ManyToOne) value, path, mappings, sessionFactoryBeanName);
        }
    } else if (currentGrailsProp.isEmbedded()) {
        value = new Component(mappings, persistentClass);
        bindComponent((Component) value, currentGrailsProp, true, mappings, sessionFactoryBeanName);
    } else {
        if (LOG.isDebugEnabled())
            LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName()
                    + "] as SimpleValue");

        value = new SimpleValue(mappings, table);
        if (currentGrailsProp.isEnum()) {
            bindEnumType(currentGrailsProp, (SimpleValue) value, path, sessionFactoryBeanName);
        } else {
            bindSimpleValue(currentGrailsProp, componentProperty, (SimpleValue) value, path, mappings,
                    sessionFactoryBeanName);
        }
    }

    if (value != null) {
        Property persistentProperty = createProperty(value, persistentClass, currentGrailsProp, mappings);
        component.addProperty(persistentProperty);
        if (isComponentPropertyNullable(componentProperty)) {
            final Iterator<?> columnIterator = value.getColumnIterator();
            while (columnIterator.hasNext()) {
                Column c = (Column) columnIterator.next();
                c.setNullable(true);
            }
        }
    }
}

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

License:Apache License

private static void bindCompositeId(GrailsDomainClass domainClass, RootClass root,
        CompositeIdentity compositeIdentity, Mappings mappings, String sessionFactoryBeanName) {
    Component id = new Component(mappings, root);
    id.setNullValue("undefined");
    root.setIdentifier(id);//from   ww  w. ja v  a2  s  .  c  om
    root.setEmbeddedIdentifier(true);
    id.setComponentClassName(domainClass.getFullName());
    id.setKey(true);
    id.setEmbedded(true);

    String path = StringHelper.qualify(root.getEntityName(), "id");

    id.setRoleName(path);

    String[] props = compositeIdentity.getPropertyNames();
    for (String propName : props) {
        GrailsDomainClassProperty property = domainClass.getPropertyByName(propName);
        if (property == null) {
            throw new MappingException(
                    "Property [" + propName + "] referenced in composite-id mapping of class ["
                            + domainClass.getFullName() + "] is not a valid property!");
        }

        bindComponentProperty(id, null, property, root, "", root.getTable(), mappings, sessionFactoryBeanName);
    }
}

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

License:Apache License

/**
 * Creates and binds the properties for the specified Grails domain class and PersistentClass
 * and binds them to the Hibernate runtime meta model
 *
 * @param domainClass     The Grails domain class
 * @param persistentClass The Hibernate PersistentClass instance
 * @param mappings        The Hibernate Mappings instance
 * @param sessionFactoryBeanName  the session factory bean name
 *///from   w w w.j ava 2  s .  c om
protected static void createClassProperties(GrailsDomainClass domainClass, PersistentClass persistentClass,
        Mappings mappings, String sessionFactoryBeanName) {

    GrailsDomainClassProperty[] persistentProperties = domainClass.getPersistentProperties();
    Table table = persistentClass.getTable();

    Mapping gormMapping = getMapping(domainClass.getClazz());

    for (GrailsDomainClassProperty currentGrailsProp : persistentProperties) {

        // if its inherited skip
        boolean isBidirectionalManyToOne = isBidirectionalManyToOne(currentGrailsProp);
        if (currentGrailsProp.isInherited()) {
            continue;
        }
        if (currentGrailsProp.isInherited() && isBidirectionalManyToOne && currentGrailsProp.isCircular()) {
            continue;
        }
        if (isCompositeIdProperty(gormMapping, currentGrailsProp))
            continue;
        if (isIdentityProperty(gormMapping, currentGrailsProp))
            continue;

        if (LOG.isDebugEnabled()) {
            LOG.debug("[GrailsDomainBinder] Binding persistent property [" + currentGrailsProp.getName() + "]");
        }

        Value value = null;

        // see if it's a collection type
        CollectionType collectionType = CollectionType.collectionTypeForClass(currentGrailsProp.getType());

        Class<?> userType = getUserType(currentGrailsProp);

        if (collectionType != null) {
            String typeName = getTypeName(currentGrailsProp, getPropertyConfig(currentGrailsProp), gormMapping);
            if (typeName != null && "serializable".equals(typeName)) {
                value = new SimpleValue(mappings, table);
                bindSimpleValue(typeName, (SimpleValue) value, currentGrailsProp.isOptional(),
                        getColumnNameForPropertyAndPath(currentGrailsProp, EMPTY_PATH, null,
                                sessionFactoryBeanName),
                        mappings);

            } else {
                // create collection
                Collection collection = collectionType.create(currentGrailsProp, persistentClass, EMPTY_PATH,
                        mappings, sessionFactoryBeanName);
                mappings.addCollection(collection);
                value = collection;
            }

        } else if (currentGrailsProp.isEnum()) {
            value = new SimpleValue(mappings, table);
            bindEnumType(currentGrailsProp, (SimpleValue) value, EMPTY_PATH, sessionFactoryBeanName);
        }
        // work out what type of relationship it is and bind value
        else if (currentGrailsProp.isManyToOne()) {
            if (LOG.isDebugEnabled())
                LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName()
                        + "] as ManyToOne");

            value = new ManyToOne(mappings, table);
            bindManyToOne(currentGrailsProp, (ManyToOne) value, EMPTY_PATH, mappings, sessionFactoryBeanName);
        } else if (currentGrailsProp.isOneToOne() && userType == null) {
            if (LOG.isDebugEnabled())
                LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName()
                        + "] as OneToOne");

            if (currentGrailsProp.isHasOne() && !currentGrailsProp.isBidirectional()) {
                throw new MappingException("hasOne property [" + currentGrailsProp.getDomainClass().getName()
                        + "." + currentGrailsProp.getName()
                        + "] is not bidirectional. Specify the other side of the relationship!");
            } else if (canBindOneToOneWithSingleColumnAndForeignKey(currentGrailsProp)) {
                value = new OneToOne(mappings, table, persistentClass);
                bindOneToOne(currentGrailsProp, (OneToOne) value, EMPTY_PATH, sessionFactoryBeanName);
            } else {
                if (currentGrailsProp.isHasOne() && currentGrailsProp.isBidirectional()) {
                    value = new OneToOne(mappings, table, persistentClass);
                    bindOneToOne(currentGrailsProp, (OneToOne) value, EMPTY_PATH, sessionFactoryBeanName);
                } else {
                    value = new ManyToOne(mappings, table);
                    bindManyToOne(currentGrailsProp, (ManyToOne) value, EMPTY_PATH, mappings,
                            sessionFactoryBeanName);
                }
            }
        } else if (currentGrailsProp.isEmbedded()) {
            value = new Component(mappings, persistentClass);

            bindComponent((Component) value, currentGrailsProp, true, mappings, sessionFactoryBeanName);
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName()
                        + "] as SimpleValue");
            }
            value = new SimpleValue(mappings, table);
            bindSimpleValue(currentGrailsProp, null, (SimpleValue) value, EMPTY_PATH, mappings,
                    sessionFactoryBeanName);
        }

        if (value != null) {
            Property property = createProperty(value, persistentClass, currentGrailsProp, mappings);
            persistentClass.addProperty(property);
        }
    }

    bindNaturalIdentifier(table, gormMapping, persistentClass);
}

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

License:Apache License

private static void bindComponentProperty(Component component, GrailsDomainClassProperty componentProperty,
        GrailsDomainClassProperty currentGrailsProp, PersistentClass persistentClass, String path, Table table,
        Mappings mappings, String sessionFactoryBeanName) {
    Value value;/*from ww w .ja  v  a 2s.com*/
    // see if it's a collection type
    CollectionType collectionType = CollectionType.collectionTypeForClass(currentGrailsProp.getType());
    if (collectionType != null) {
        // create collection

        Collection collection = collectionType.create(currentGrailsProp, persistentClass, path, mappings,
                sessionFactoryBeanName);
        mappings.addCollection(collection);
        value = collection;
    }
    // work out what type of relationship it is and bind value
    else if (currentGrailsProp.isManyToOne()) {
        if (LOG.isDebugEnabled())
            LOG.debug(
                    "[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as ManyToOne");

        value = new ManyToOne(mappings, table);
        bindManyToOne(currentGrailsProp, (ManyToOne) value, path, mappings, sessionFactoryBeanName);
    } else if (currentGrailsProp.isOneToOne()) {
        if (LOG.isDebugEnabled())
            LOG.debug(
                    "[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as OneToOne");

        if (canBindOneToOneWithSingleColumnAndForeignKey(currentGrailsProp)) {
            value = new OneToOne(mappings, table, persistentClass);
            bindOneToOne(currentGrailsProp, (OneToOne) value, path, sessionFactoryBeanName);
        } else {
            value = new ManyToOne(mappings, table);
            bindManyToOne(currentGrailsProp, (ManyToOne) value, path, mappings, sessionFactoryBeanName);
        }
    } else if (currentGrailsProp.isEmbedded()) {
        value = new Component(mappings, persistentClass);
        bindComponent((Component) value, currentGrailsProp, true, mappings, sessionFactoryBeanName);
    } else {
        if (LOG.isDebugEnabled())
            LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName()
                    + "] as SimpleValue");

        value = new SimpleValue(mappings, table);
        if (currentGrailsProp.isEnum()) {
            bindEnumType(currentGrailsProp, (SimpleValue) value, path, sessionFactoryBeanName);
        } else {
            bindSimpleValue(currentGrailsProp, componentProperty, (SimpleValue) value, path, mappings,
                    sessionFactoryBeanName);
        }
    }

    if (value != null) {
        Property persistentProperty = createProperty(value, persistentClass, currentGrailsProp, mappings);
        component.addProperty(persistentProperty);
        if (isComponentPropertyNullable(componentProperty)) {
            final Iterator<?> columnIterator = value.getColumnIterator();
            while (columnIterator.hasNext()) {
                Column c = (Column) columnIterator.next();
                c.setNullable(true);
            }
        }
    }
}

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

License:Apache License

protected void bindCompositeId(PersistentEntity domainClass, RootClass root,
        CompositeIdentity compositeIdentity, Mappings mappings, String sessionFactoryBeanName) {
    HibernatePersistentEntity hibernatePersistentEntity = (HibernatePersistentEntity) domainClass;
    Component id = new Component(mappings, root);
    id.setNullValue("undefined");
    root.setIdentifier(id);/*from w  ww.  ja  va  2 s .  c om*/
    root.setEmbeddedIdentifier(true);
    id.setComponentClassName(domainClass.getName());
    id.setKey(true);
    id.setEmbedded(true);

    String path = qualify(root.getEntityName(), "id");

    id.setRoleName(path);

    final PersistentProperty[] composite = hibernatePersistentEntity.getCompositeIdentity();
    for (PersistentProperty property : composite) {
        if (property == null) {
            throw new MappingException("Property referenced in composite-id mapping of class ["
                    + domainClass.getName() + "] is not a valid property!");
        }

        bindComponentProperty(id, null, property, root, "", root.getTable(), mappings, sessionFactoryBeanName);
    }
}