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 10
10
import org .hibernate .dialect .Dialect ;
11
11
import org .hibernate .internal .util .StringHelper ;
12
12
13
+ import org .jboss .logging .Logger ;
14
+
13
15
/**
14
16
* A primary key constraint
17
+ *
15
18
* @author Gavin King
19
+ * @author Steve Ebersole
16
20
*/
17
21
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
+ }
18
49
19
50
public String sqlConstraintString (Dialect dialect ) {
20
51
StringBuilder buf = new StringBuilder ("primary key (" );
You can’t perform that action at this time.
0 commit comments