Java Code Examples for org.hibernate.mapping.Table#addUniqueKey()

The following examples show how to use org.hibernate.mapping.Table#addUniqueKey() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
protected void bindNaturalIdentifier(Table table, Mapping mapping, PersistentClass persistentClass) {
    Object o = mapping != null ? mapping.getIdentity() : null;
    if (!(o instanceof Identity)) {
        return;
    }

    Identity identity = (Identity) o;
    final NaturalId naturalId = identity.getNatural();
    if (naturalId == null || naturalId.getPropertyNames().isEmpty()) {
        return;
    }

    UniqueKey uk = new UniqueKey();
    uk.setTable(table);

    boolean mutable = naturalId.isMutable();

    for (String propertyName : naturalId.getPropertyNames()) {
        Property property = persistentClass.getProperty(propertyName);

        property.setNaturalIdentifier(true);
        if (!mutable) property.setUpdateable(false);

        uk.addColumns(property.getColumnIterator());
    }

    setGeneratedUniqueName(uk);

    table.addUniqueKey(uk);
}
 
Example 2
protected void createUniqueKeyForColumns(Table table, String columnName, List<Column> columns) {
    Collections.reverse(columns);

    UniqueKey uk = new UniqueKey();
    uk.setTable(table);
    uk.addColumns(columns.iterator());

    if(LOG.isDebugEnabled()) {
        LOG.debug("create unique key for " + table.getName() + " columns = " + columns);
    }
    setGeneratedUniqueName(uk);
    table.addUniqueKey(uk);
}