mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-24 20:36:28 +00:00
HHH-8178 Natural IDs generate one UniqueKey for all columns
This commit is contained in:
parent
e63dc96b13
commit
486cac2174
@ -2096,12 +2096,12 @@ else if ( !isId || !entityBinder.isIgnoreIdAnnotations() ) {
|
||||
if ( naturalIdAnn != null ) {
|
||||
if ( joinColumns != null ) {
|
||||
for ( Ejb3Column column : joinColumns ) {
|
||||
column.addUniqueKey( StringHelper.randomFixedLengthHex("UK_"), inSecondPass );
|
||||
column.addUniqueKey( column.getTable().getNaturalIdUniqueKeyName(), inSecondPass );
|
||||
}
|
||||
}
|
||||
else {
|
||||
for ( Ejb3Column column : columns ) {
|
||||
column.addUniqueKey( StringHelper.randomFixedLengthHex("UK_"), inSecondPass );
|
||||
column.addUniqueKey( column.getTable().getNaturalIdUniqueKeyName(), inSecondPass );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,6 +69,15 @@ public class Table implements RelationalModel, Serializable {
|
||||
private boolean isAbstract;
|
||||
private boolean hasDenormalizedTables = false;
|
||||
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 {
|
||||
String referencedClassName;
|
||||
@ -817,6 +826,10 @@ public void setComment(String comment) {
|
||||
public Iterator getCheckConstraintsIterator() {
|
||||
return checkConstraints.iterator();
|
||||
}
|
||||
|
||||
public String getNaturalIdUniqueKeyName() {
|
||||
return naturalIdUniqueKeyName;
|
||||
}
|
||||
|
||||
public Iterator sqlCommentStrings(Dialect dialect, String defaultCatalog, String defaultSchema) {
|
||||
List comments = new ArrayList();
|
||||
|
Loading…
x
Reference in New Issue
Block a user