HHH-9798 - Fix Unique constraint of @JoinColumn in @JoinTable not generated

This commit is contained in:
Andrea Boriero 2015-05-26 14:54:58 +01:00
parent fdd7fb8080
commit fff9a16a22
1 changed files with 12 additions and 0 deletions

View File

@ -17,7 +17,9 @@ import org.hibernate.boot.model.relational.QualifiedNameParser;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.mapping.Column; import org.hibernate.mapping.Column;
import org.hibernate.mapping.Constraint;
import org.hibernate.mapping.Table; import org.hibernate.mapping.Table;
import org.hibernate.mapping.UniqueKey;
import org.hibernate.tool.schema.spi.Exporter; import org.hibernate.tool.schema.spi.Exporter;
/** /**
@ -105,6 +107,16 @@ public class StandardTableExporter implements Exporter<Table> {
} }
if ( col.isUnique() ) {
String keyName = Constraint.generateName( "UK_", table, col );
UniqueKey uk = table.getOrCreateUniqueKey( keyName );
uk.addColumn( col );
buf.append(
dialect.getUniqueDelegate()
.getColumnDefinitionUniquenessFragment( col )
);
}
if ( col.getCheckConstraint() != null && dialect.supportsColumnCheck() ) { if ( col.getCheckConstraint() != null && dialect.supportsColumnCheck() ) {
buf.append( " check (" ) buf.append( " check (" )
.append( col.getCheckConstraint() ) .append( col.getCheckConstraint() )