Skip to content

Commit 3c5913b

Browse files
committed
HHH-19328 introduce @NaturalIdClass
1 parent b2b179a commit 3c5913b

File tree

15 files changed

+417
-69
lines changed

15 files changed

+417
-69
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.annotations;
6+
7+
import java.lang.annotation.Retention;
8+
import java.lang.annotation.Target;
9+
10+
import static java.lang.annotation.ElementType.TYPE;
11+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
12+
13+
@Target(TYPE)
14+
@Retention(RUNTIME)
15+
public @interface NaturalIdClass {
16+
Class<?> value();
17+
}

hibernate-core/src/main/java/org/hibernate/boot/model/internal/ComponentPropertyHolder.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,12 @@ public Column[] getOverriddenColumn(String propertyName) {
330330
result = super.getOverriddenColumn( userPropertyName );
331331
}
332332
}
333+
if ( result == null ) {
334+
final String userPropertyName = extractUserPropertyName( "natural_id", propertyName );
335+
if ( userPropertyName != null ) {
336+
result = super.getOverriddenColumn( userPropertyName );
337+
}
338+
}
333339
if ( result == null ) {
334340
final String userPropertyName = extractUserPropertyName( IDENTIFIER_MAPPER_PROPERTY, propertyName );
335341
if ( userPropertyName != null ) {
@@ -340,8 +346,8 @@ public Column[] getOverriddenColumn(String propertyName) {
340346
}
341347

342348
private String extractUserPropertyName(String redundantString, String propertyName) {
343-
String className = component.getOwner().getClassName();
344-
boolean specialCase = propertyName.startsWith(className)
349+
final String className = component.getOwner().getClassName();
350+
final boolean specialCase = propertyName.startsWith(className)
345351
&& propertyName.length() > className.length() + 2 + redundantString.length() // .id.
346352
&& propertyName.substring( className.length() + 1, className.length() + 1 + redundantString.length() )
347353
.equals(redundantString);

0 commit comments

Comments
 (0)