Skip to content

Commit

Permalink
Fix missing reflection for some generator classes in Hibernate ORM
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Jun 21, 2024
1 parent 6f818f8 commit 171f3df
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,17 @@ private static DotName createConstant(String fqcn) {
createConstant("org.hibernate.generator.internal.TenantIdGeneration"),
createConstant("org.hibernate.generator.internal.VersionGeneration"),
createConstant("org.hibernate.id.Assigned"),
createConstant("org.hibernate.id.CompositeNestedGeneratedValueGenerator"),
createConstant("org.hibernate.id.ForeignGenerator"),
createConstant("org.hibernate.id.GUIDGenerator"),
createConstant("org.hibernate.id.IdentityGenerator"),
createConstant("org.hibernate.id.IncrementGenerator"),
createConstant("org.hibernate.id.SelectGenerator"),
createConstant("org.hibernate.id.UUIDGenerator"),
createConstant("org.hibernate.id.UUIDHexGenerator"),
createConstant("org.hibernate.id.enhanced.SequenceStyleGenerator"),
createConstant("org.hibernate.id.enhanced.TableGenerator"),
createConstant("org.hibernate.id.uuid.UuidGenerator"),
createConstant("org.hibernate.tuple.CreationTimestampGeneration"),
createConstant("org.hibernate.tuple.UpdateTimestampGeneration"),
createConstant("org.hibernate.tuple.VmValueGeneration"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ private static Set<DotName> provideConstantsToTest() {
return ClassNames.CREATED_CONSTANTS;
}

@Test
public void testNoMissingGeneratorClass() {
Set<DotName> generatorImplementors = findConcreteNamedImplementors(hibernateIndex, "org.hibernate.generator.Generator");

assertThat(ClassNames.GENERATORS)
.containsExactlyInAnyOrderElementsOf(generatorImplementors);
}

@Test
public void testNoMissingJpaAnnotation() {
Set<DotName> jpaMappingAnnotations = findRuntimeAnnotations(jpaIndex);
Expand Down Expand Up @@ -191,6 +199,17 @@ private boolean allowsTargetType(ClassInfo annotation, ElementType targetType) {
return allowedTargetTypes.contains(targetType.name());
}

private Set<DotName> findConcreteNamedImplementors(Index index, String interfaceName) {
var interfaceDotName = DotName.createSimple(interfaceName);
assertThat(index.getClassByName(interfaceDotName)).isNotNull();
return index.getAllKnownImplementors(interfaceDotName).stream()
.filter(c -> !c.isInterface() && !c.isAbstract()
// Ignore anonymous classes
&& c.simpleName() != null)
.map(ClassInfo::name)
.collect(Collectors.toSet());
}

private static File determineJpaJarLocation() {
URL url = EntityManager.class.getProtectionDomain().getCodeSource().getLocation();
if (!url.getProtocol().equals("file")) {
Expand Down

0 comments on commit 171f3df

Please sign in to comment.