Skip to content

Commit 1ae495b

Browse files
committed
HHH-10045 - Teradata requires non null primary keys.
(cherry picked from commit e8da2d0)
1 parent 4223e43 commit 1ae495b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

hibernate-core/src/main/java/org/hibernate/mapping/PrimaryKey.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,42 @@
1010
import org.hibernate.dialect.Dialect;
1111
import org.hibernate.internal.util.StringHelper;
1212

13+
import org.jboss.logging.Logger;
14+
1315
/**
1416
* A primary key constraint
17+
*
1518
* @author Gavin King
19+
* @author Steve Ebersole
1620
*/
1721
public class PrimaryKey extends Constraint {
22+
private static final Logger log = Logger.getLogger( PrimaryKey.class );
23+
24+
@Override
25+
public void addColumn(Column column) {
26+
if ( column.isNullable() ) {
27+
if ( log.isDebugEnabled() ) {
28+
final String columnName = column.getCanonicalName();
29+
log.debugf(
30+
"Forcing column [%s] to be non-null as it is part of the primary key for table [%s]",
31+
columnName,
32+
getTableNameForLogging( column )
33+
);
34+
}
35+
column.setNullable( false );
36+
}
37+
super.addColumn( column );
38+
}
39+
40+
protected String getTableNameForLogging(Column column) {
41+
if ( getTable() != null ) {
42+
return getTable().getNameIdentifier().getCanonicalName();
43+
}
44+
else if ( column.getValue() != null && column.getValue().getTable() != null ) {
45+
return column.getValue().getTable().getNameIdentifier().getCanonicalName();
46+
}
47+
return "<unknown>";
48+
}
1849

1950
public String sqlConstraintString(Dialect dialect) {
2051
StringBuilder buf = new StringBuilder("primary key (");

0 commit comments

Comments
 (0)