File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
hibernate-core/src/main/java/org/hibernate/mapping Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1010import org .hibernate .dialect .Dialect ;
1111import 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 */
1721public 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 (" );
You can’t perform that action at this time.
0 commit comments