Skip to content

Commit 8d4de09

Browse files
committed
HHH-14241 Support ImplicitNamingStrategyComponentPathImpl with IdClass
Signed-off-by: Jan Schatteman <[email protected]>
1 parent 03416a8 commit 8d4de09

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/naming/ImplicitNamingStrategyComponentPathImpl.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import org.hibernate.boot.model.source.spi.AttributePath;
1010
import org.hibernate.internal.util.StringHelper;
11+
import org.hibernate.loader.PropertyPath;
1112

1213
/**
1314
* An ImplicitNamingStrategy implementation which uses full composite paths
@@ -30,14 +31,17 @@ protected String transformAttributePath(AttributePath attributePath) {
3031
}
3132

3233
public static void process(AttributePath attributePath, StringBuilder sb) {
33-
if ( attributePath.getParent() != null ) {
34-
process( attributePath.getParent(), sb );
35-
if ( StringHelper.isNotEmpty( attributePath.getParent().getProperty() ) ) {
36-
sb.append( '_' );
37-
}
38-
}
39-
4034
String property = attributePath.getProperty();
35+
final AttributePath parent = attributePath.getParent();
36+
if ( parent != null && StringHelper.isNotEmpty( parent.getProperty() ) ) {
37+
process( parent, sb );
38+
sb.append( '_' );
39+
}
40+
else if ( PropertyPath.IDENTIFIER_MAPPER_PROPERTY.equals( property ) ) {
41+
// skip it, do not pass go
42+
sb.append( "id" );
43+
return;
44+
}
4145
property = property.replace( "<", "" );
4246
property = property.replace( ">", "" );
4347

hibernate-core/src/test/java/org/hibernate/id/idclass/IdClassNamingStrategyTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl;
1010
import org.hibernate.cfg.Configuration;
1111

12+
import org.hibernate.testing.TestForIssue;
1213
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
1314
import org.junit.Test;
1415

@@ -21,22 +22,23 @@ protected Class<?>[] getAnnotatedClasses() {
2122

2223
@Override
2324
protected void configure(Configuration configuration) {
24-
/*
25-
* With this implicit naming strategy, we got the following mapping:
26-
*
27-
* create table MyEntity (
25+
/*
26+
* With this implicit naming strategy, we got the following mapping:
27+
*
28+
* create table MyEntity (
2829
* id_idA bigint not null,
2930
* id_idB bigint not null,
3031
* _identifierMapper_idA bigint not null, <-- ??
3132
* _identifierMapper_idB bigint not null, <-- ??
3233
* notes varchar(255),
3334
* primary key (id_idA, id_idB)
3435
* )
35-
*/
36+
*/
3637
configuration.setImplicitNamingStrategy( new ImplicitNamingStrategyComponentPathImpl() );
3738
}
3839

3940
@Test
41+
@TestForIssue(jiraKey = "HHH-14241")
4042
public void test() {
4143
inTransaction( ( session ) -> {
4244
MyEntity entity = new MyEntity();

hibernate-core/src/test/java/org/hibernate/id/idclass/MyEntity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ public class MyEntity {
2323
private String notes;
2424

2525
public MyEntityId getId() {
26-
return new MyEntityId( idB, idA );
26+
return new MyEntityId( idA, idB );
2727
}
2828

2929
public void setId(MyEntityId id) {
30-
this.idB = id.getIdA();
31-
this.idA = id.getIdB();
30+
this.idA = id.getIdA();
31+
this.idB = id.getIdB();
3232
}
3333

3434
public String getNotes() {

0 commit comments

Comments
 (0)