Skip to content

Commit a332dd7

Browse files
committed
HHH-18829 Test - order of record components must match order of properties in entity class
1 parent fcbc30e commit a332dd7

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/hhh18829/HHH18829Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void setUp(SessionFactoryScope sessionFactoryScope) {
4141
public void test(SessionFactoryScope sessionFactoryScope)
4242
throws ClassNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException {
4343
final var idClass = Class.forName( EmployeeWithoutIdClass.class.getName() + "_$Id" );
44-
final var id = idClass.getConstructors()[0].newInstance( 1, "John Doe" );
44+
final var id = idClass.getConstructors()[0].newInstance( "John Doe", 1 );
4545
final var employees = sessionFactoryScope.fromSession(
4646
sess -> sess.createQuery( "from EmployeeWithoutIdClass where id=:id", EmployeeWithoutIdClass.class ).setParameter( "id", id )
4747
.getResultList()

tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/hhh18829/AnotherEmployee.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,9 @@
99

1010
@Entity
1111
public class AnotherEmployee extends Address {
12-
String empName;
13-
1412
Integer empId;
1513

16-
@Id
17-
public String getEmpName() {
18-
return empName;
19-
}
20-
21-
public void setEmpName(String empName) {
22-
this.empName = empName;
23-
}
14+
String empName;
2415

2516
@Id
2617
public Integer getEmpId() {
@@ -30,4 +21,13 @@ public Integer getEmpId() {
3021
public void setEmpId(Integer empId) {
3122
this.empId = empId;
3223
}
24+
25+
@Id
26+
public String getEmpName() {
27+
return empName;
28+
}
29+
30+
public void setEmpName(String empName) {
31+
this.empName = empName;
32+
}
3333
}

tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/hhh18829/HHH18829Test.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
import org.hibernate.processor.test.util.WithClasses;
1111
import org.junit.Test;
1212

13+
import java.lang.reflect.RecordComponent;
1314
import java.util.Arrays;
1415

1516
import static org.hibernate.processor.test.util.TestUtil.getMetamodelClassFor;
17+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
1618
import static org.junit.jupiter.api.Assertions.assertTrue;
1719

1820
@TestForIssue(jiraKey = " HHH-18829")
@@ -27,23 +29,25 @@ public void test() {
2729
System.out.println( TestUtil.getMetaModelSourceAsString( Address.class ) );
2830
System.out.println( TestUtil.getMetaModelSourceAsString( EmployeeWithIdClass.class ) );
2931

30-
checkIfIdClassIsGenerated( Employee.class );
31-
checkIfIdClassIsGenerated( AnotherEmployee.class );
32+
checkIfIdClassIsGenerated( Employee.class, new String[] {"empName", "empId"} );
33+
checkIfIdClassIsGenerated( AnotherEmployee.class, new String[] {"empId", "empName"} );
3234

3335
final var clazz = getMetamodelClassFor( EmployeeWithIdClass.class );
3436
assertTrue( Arrays.stream( clazz.getClasses() ).map( Class::getSimpleName )
3537
.noneMatch( "Id"::equals ),
3638
"EmployeeWithIdClass_ should not have inner class Id" );
3739
}
3840

39-
private static void checkIfIdClassIsGenerated(Class<?> entityClass) {
41+
private static void checkIfIdClassIsGenerated(Class<?> entityClass, String[] idComponentNames) {
4042
final var clazz = getMetamodelClassFor( entityClass );
4143
final var maybeIdClass = Arrays.stream( clazz.getClasses() )
4244
.filter( c -> c.getSimpleName().equals( "Id" ) ).findAny();
4345
assertTrue( maybeIdClass.isPresent(), () -> clazz.getSimpleName() + "_ should have inner class Id" );
4446
final Class<?> idClass = maybeIdClass.get();
4547
assertTrue( idClass.isRecord(), "Generated ID class should be a record" );
46-
final var recordComponents = idClass.getRecordComponents();
47-
// TODO : Check record components
48+
assertArrayEquals(
49+
idComponentNames,
50+
Arrays.stream( idClass.getRecordComponents() ).map( RecordComponent::getName ).toArray( String[]::new )
51+
);
4852
}
4953
}

0 commit comments

Comments
 (0)