Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.processor.test.data.constraint;

import org.hibernate.processor.test.util.CompilationTest;
import org.hibernate.processor.test.util.WithClasses;
import org.junit.jupiter.api.Test;

import static org.hibernate.processor.test.util.TestUtil.assertMetamodelClassGeneratedFor;
import static org.hibernate.processor.test.util.TestUtil.getMetaModelSourceAsString;

@CompilationTest
class DataTest {
@Test
@WithClasses({MyEntity.class, MyConstrainedRepository.class})
void test() {
System.out.println( getMetaModelSourceAsString( MyEntity.class ) );
System.out.println( getMetaModelSourceAsString( MyConstrainedRepository.class ) );
assertMetamodelClassGeneratedFor( MyEntity.class );
assertMetamodelClassGeneratedFor( MyConstrainedRepository.class );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.processor.test.data.constraint;

import jakarta.data.repository.CrudRepository;
import jakarta.data.repository.Find;
import jakarta.data.repository.Repository;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;

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

@Valid
@NotNull
@Find
MyEntity findByName(@NotNull @Size(min = 5) String name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.processor.test.data.constraint;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;

@Entity
public class MyEntity {

@Id
private Long id;
@Column(unique = true)
private String name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2065,7 +2065,7 @@ private void createCriteriaFinder(
new CriteriaFinderMethod(
this, method,
methodName,
returnType.toString(),
typeAsString( returnType, false ),
containerType,
paramNames,
paramTypes,
Expand Down Expand Up @@ -2378,7 +2378,7 @@ && matchesNaturalKey( entity, fieldTypes ) ) {
new CriteriaFinderMethod(
this, method,
methodName,
returnType.toString(),
typeAsString( returnType, false ),
containerType,
paramNames,
paramTypes,
Expand Down Expand Up @@ -2482,7 +2482,7 @@ private void createSingleParameterFinder(
new CriteriaFinderMethod(
this, method,
methodName,
returnType.toString(),
typeAsString( returnType, false ),
containerType,
paramNames,
paramTypes,
Expand Down Expand Up @@ -3426,19 +3426,35 @@ private List<String> parameterTypes(ExecutableElement method) {
* Workaround for a bug in Java 20/21. Should not be necessary!
*/
private String typeAsString(TypeMirror type) {
String result = type.toString();
for ( AnnotationMirror annotation : type.getAnnotationMirrors() ) {
final String annotationString = annotation.toString();
result = result
// if it has a space after it, we need to remove that too
.replace(annotationString + ' ', "")
// just in case it did not have a space after it
.replace(annotationString, "");
}
for ( AnnotationMirror annotation : type.getAnnotationMirrors() ) {
result = annotation.toString() + ' ' + result;
return typeAsString( type, true );
}

private String typeAsString(TypeMirror type, boolean includeAnnotations) {
if ( type instanceof DeclaredType dt && dt.asElement() instanceof TypeElement te ) {
StringBuilder result = new StringBuilder();
if ( includeAnnotations ) {
for ( AnnotationMirror annotation : type.getAnnotationMirrors() ) {
result.append( annotation.toString() ).append( ' ' );
}
}
// get the "fqcn" without any type arguments
result.append( te.getQualifiedName().toString() );
// add the < ? ,? ....> as necessary:
if ( !dt.getTypeArguments().isEmpty() ) {
result.append( "<" );
int index = 0;
for ( ; index < dt.getTypeArguments().size() - 1; index++ ) {
result.append( typeAsString( dt.getTypeArguments().get( index ), true ) )
.append( ", " );
}
result.append( typeAsString( dt.getTypeArguments().get( index ), true ) );
result.append( ">" );
}
return result.toString();
}
else {
return type.toString();
}
return result;
}

private TypeMirror parameterType(VariableElement parameter) {
Expand Down