HHH-10045 - Teradata requires non null primary keys.

This commit is contained in:
Steve Ebersole 2015-09-24 13:00:39 -05:00
parent 4777d5888c
commit e8da2d09b3
1 changed files with 31 additions and 0 deletions

View File

@ -10,11 +10,42 @@ import java.util.Iterator;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;
import org.jboss.logging.Logger;
/** /**
* A primary key constraint * A primary key constraint
*
* @author Gavin King * @author Gavin King
* @author Steve Ebersole
*/ */
public class PrimaryKey extends Constraint { public class PrimaryKey extends Constraint {
private static final Logger log = Logger.getLogger( PrimaryKey.class );
@Override
public void addColumn(Column column) {
if ( column.isNullable() ) {
if ( log.isDebugEnabled() ) {
final String columnName = column.getCanonicalName();
log.debugf(
"Forcing column [%s] to be non-null as it is part of the primary key for table [%s]",
columnName,
getTableNameForLogging( column )
);
}
column.setNullable( false );
}
super.addColumn( column );
}
protected String getTableNameForLogging(Column column) {
if ( getTable() != null ) {
return getTable().getNameIdentifier().getCanonicalName();
}
else if ( column.getValue() != null && column.getValue().getTable() != null ) {
return column.getValue().getTable().getNameIdentifier().getCanonicalName();
}
return "<unknown>";
}
public String sqlConstraintString(Dialect dialect) { public String sqlConstraintString(Dialect dialect) {
StringBuilder buf = new StringBuilder("primary key ("); StringBuilder buf = new StringBuilder("primary key (");