Skip to content

Commit c345a55

Browse files
committed
HHH-19630 Adjust how Hibernate Processor determines the entity type
1 parent 1eea2ea commit c345a55

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/data/constraint/DataTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ void test() {
1919
System.out.println( getMetaModelSourceAsString( MyEntity.class ) );
2020
System.out.println( getMetaModelSourceAsString( MyConstrainedRepository.class ) );
2121
assertMetamodelClassGeneratedFor( MyEntity.class );
22-
// assertMetamodelClassGeneratedFor( MyConstrainedRepository.class );
22+
assertMetamodelClassGeneratedFor( MyConstrainedRepository.class );
2323
}
2424
}

tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/data/constraint/MyConstrainedRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
import jakarta.data.repository.CrudRepository;
88
import jakarta.data.repository.Find;
99
import jakarta.data.repository.Repository;
10+
import jakarta.validation.Valid;
1011
import jakarta.validation.constraints.NotNull;
1112
import jakarta.validation.constraints.Size;
1213

1314
@Repository
1415
public interface MyConstrainedRepository extends CrudRepository<MyEntity, Long> {
1516

17+
@Valid
18+
@NotNull
1619
@Find
1720
MyEntity findByName(@NotNull @Size(min = 5) String name);
1821
}

tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/data/constraint/MyEntity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
package org.hibernate.processor.test.data.constraint;
66

7+
import jakarta.persistence.Column;
78
import jakarta.persistence.Entity;
89
import jakarta.persistence.Id;
910

@@ -12,5 +13,6 @@ public class MyEntity {
1213

1314
@Id
1415
private Long id;
16+
@Column(unique = true)
1517
private String name;
1618
}

tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,7 +2453,7 @@ private void createSingleParameterFinder(
24532453
new CriteriaFinderMethod(
24542454
this, method,
24552455
methodName,
2456-
returnType.toString(),
2456+
typeAsString( returnType, false ),
24572457
containerType,
24582458
paramNames,
24592459
paramTypes,
@@ -3389,25 +3389,29 @@ private List<String> parameterTypes(ExecutableElement method) {
33893389
* Workaround for a bug in Java 20/21. Should not be necessary!
33903390
*/
33913391
private String typeAsString(TypeMirror type) {
3392-
String result;
3392+
return typeAsString( type, true );
3393+
}
3394+
3395+
private String typeAsString(TypeMirror type, boolean includeAnnotations) {
33933396
if ( type instanceof DeclaredType dt && dt.asElement() instanceof TypeElement te ) {
33943397
// get the "fqcn" without any type arguments
3395-
result = te.getQualifiedName().toString();
3398+
String result = te.getQualifiedName().toString();
33963399
// add the < ? ,? ....> as necessary:
33973400
if ( !dt.getTypeArguments().isEmpty() ) {
33983401
result += dt.getTypeArguments().stream()
3399-
.map( this::typeAsString )
3400-
.collect( Collectors.joining( ",", "<", ">" ) );
3402+
.map( arg -> typeAsString( arg, true ) )
3403+
.collect( Collectors.joining( ", ", "<", ">" ) );
3404+
}
3405+
if ( includeAnnotations ) {
3406+
for ( AnnotationMirror annotation : type.getAnnotationMirrors() ) {
3407+
result = annotation.toString() + ' ' + result;
3408+
}
34013409
}
3410+
return result;
34023411
}
34033412
else {
3404-
result = type.toString();
3405-
}
3406-
3407-
for ( AnnotationMirror annotation : type.getAnnotationMirrors() ) {
3408-
result = annotation.toString() + ' ' + result;
3413+
return type.toString();
34093414
}
3410-
return result;
34113415
}
34123416

34133417
private TypeMirror parameterType(VariableElement parameter) {

0 commit comments

Comments
 (0)