HHH-8178 Natural IDs generate one UniqueKey for all columns
This commit is contained in:
parent
d39272a280
commit
53f7b73adb
|
@ -2106,12 +2106,12 @@ public final class AnnotationBinder {
|
||||||
if ( naturalIdAnn != null ) {
|
if ( naturalIdAnn != null ) {
|
||||||
if ( joinColumns != null ) {
|
if ( joinColumns != null ) {
|
||||||
for ( Ejb3Column column : joinColumns ) {
|
for ( Ejb3Column column : joinColumns ) {
|
||||||
column.addUniqueKey( StringHelper.randomFixedLengthHex("UK_"), inSecondPass );
|
column.addUniqueKey( column.getTable().getNaturalIdUniqueKeyName(), inSecondPass );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for ( Ejb3Column column : columns ) {
|
for ( Ejb3Column column : columns ) {
|
||||||
column.addUniqueKey( StringHelper.randomFixedLengthHex("UK_"), inSecondPass );
|
column.addUniqueKey( column.getTable().getNaturalIdUniqueKeyName(), inSecondPass );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,15 @@ public class Table implements RelationalModel, Serializable {
|
||||||
private boolean isAbstract;
|
private boolean isAbstract;
|
||||||
private boolean hasDenormalizedTables = false;
|
private boolean hasDenormalizedTables = false;
|
||||||
private String comment;
|
private String comment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Natural ID columns must reside in one single UniqueKey within the Table.
|
||||||
|
* To prevent separate UniqueKeys from being created, this keeps track of
|
||||||
|
* a sole name used for all of them. It's necessary since
|
||||||
|
* AnnotationBinder#processElementAnnotations (static) creates the
|
||||||
|
* UniqueKeys on a second pass using randomly-generated names.
|
||||||
|
*/
|
||||||
|
private final String naturalIdUniqueKeyName = StringHelper.randomFixedLengthHex( "UK_" );
|
||||||
|
|
||||||
static class ForeignKeyKey implements Serializable {
|
static class ForeignKeyKey implements Serializable {
|
||||||
String referencedClassName;
|
String referencedClassName;
|
||||||
|
@ -818,6 +827,10 @@ public class Table implements RelationalModel, Serializable {
|
||||||
public Iterator getCheckConstraintsIterator() {
|
public Iterator getCheckConstraintsIterator() {
|
||||||
return checkConstraints.iterator();
|
return checkConstraints.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getNaturalIdUniqueKeyName() {
|
||||||
|
return naturalIdUniqueKeyName;
|
||||||
|
}
|
||||||
|
|
||||||
public Iterator sqlCommentStrings(Dialect dialect, String defaultCatalog, String defaultSchema) {
|
public Iterator sqlCommentStrings(Dialect dialect, String defaultCatalog, String defaultSchema) {
|
||||||
List comments = new ArrayList();
|
List comments = new ArrayList();
|
||||||
|
|
Loading…
Reference in New Issue