-
Notifications
You must be signed in to change notification settings - Fork 3k
Added class name check to remove warning #50722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
3c203fb
b833f13
fd68642
2fe0271
f2f0fb5
e83711e
f61a352
d0925a7
06ab0bb
3023296
0040b6f
91756cd
25201f3
c7b878e
573a771
795141c
3569463
a504778
0d3395e
9eb8296
3e8012c
cf20244
55b3d5b
4acd473
b0fdb6a
788b4ba
cd13282
6670cfd
74f3ad8
2656170
7be850c
202b4c3
194edb6
7de7920
c3b4d8d
d87beba
2906258
0d2843b
2e7f396
999771b
672df7f
058b7fe
65f407f
17564d8
b1f2272
a8a4190
ce05361
234c81f
e3e0b8d
131d7bc
e9d1e56
41e309e
b2acb6c
2f9f1e5
ccb8867
bf78cb7
fd62eaf
5ac20db
44c590d
bb1cfa0
b931128
85f36b9
cf9b1bf
ba27383
86ea3f3
3955d11
06261a5
29b5b02
ea75990
d7197db
ebd7bbf
a57e9c8
f041f7c
9bd29fb
1a7f60a
8fce8ae
720f194
edd7a8f
b8454af
59bc814
fd70b63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -471,6 +471,7 @@ public BytecodeRecorderConstantDefinitionBuildItem pregenProxies( | |
| LiveReloadBuildItem liveReloadBuildItem, | ||
| ExecutorService buildExecutor) throws ExecutionException, InterruptedException { | ||
| Set<String> managedClassAndPackageNames = new HashSet<>(jpaModel.getEntityClassNames()); | ||
| Set<String> managedClassesName = new HashSet<>(jpaModel.getEntityClassNames()); | ||
| for (PersistenceUnitDescriptorBuildItem pud : persistenceUnitDescriptorBuildItems) { | ||
| // Note: getManagedClassNames() can also return *package* names | ||
| // See the source code of Hibernate ORM for proof: | ||
|
|
@@ -481,9 +482,10 @@ public BytecodeRecorderConstantDefinitionBuildItem pregenProxies( | |
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You also need to update the Now, obviously you cannot use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I then believe sir, we have to add one more data member inside If it seems ok, may I proceed with those changes ?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes this seems perfectly reasonable :) |
||
| for (AdditionalJpaModelBuildItem additionalJpaModelBuildItem : additionalJpaModelBuildItems) { | ||
| managedClassAndPackageNames.add(additionalJpaModelBuildItem.getClassName()); | ||
| managedClassesName.add(additionalJpaModelBuildItem.getClassName()); | ||
| } | ||
|
|
||
| PreGeneratedProxies proxyDefinitions = generateProxies(managedClassAndPackageNames, | ||
| PreGeneratedProxies proxyDefinitions = generateProxies(managedClassAndPackageNames, managedClassesName, | ||
|
||
| indexBuildItem.getIndex(), transformedClassesBuildItem, | ||
| generatedClassBuildItemBuildProducer, liveReloadBuildItem, buildExecutor); | ||
|
|
||
|
|
@@ -1155,6 +1157,11 @@ public static Map<String, JpaPersistenceUnitModel> getModelPerPersistenceUnit(Hi | |
| IndexView index, boolean enableDefaultPersistenceUnit) { | ||
| Map<String, JpaPersistenceUnitModel> modelPerPersistenceUnit = new HashMap<>(); | ||
|
|
||
| Set<String> managedClassNames = new HashSet<>(jpaModel.getEntityClassNames()); | ||
| for (AdditionalJpaModelBuildItem additionalJpaModel : additionalJpaModelBuildItems) { | ||
| managedClassNames.add(additionalJpaModel.getClassName()); | ||
| } | ||
|
|
||
| boolean hasPackagesInQuarkusConfig = hasPackagesInQuarkusConfig(hibernateOrmConfig); | ||
| Collection<AnnotationInstance> packageLevelPersistenceUnitAnnotations = getPackageLevelPersistenceUnitAnnotations( | ||
| index); | ||
|
|
@@ -1229,13 +1236,19 @@ public static Map<String, JpaPersistenceUnitModel> getModelPerPersistenceUnit(Hi | |
| Set<String> modelClassesWithPersistenceUnitAnnotations = new TreeSet<>(); | ||
|
|
||
| for (String modelClassName : jpaModel.getAllModelClassNames()) { | ||
| ClassInfo modelClassInfo = index.getClassByName(DotName.createSimple(modelClassName)); | ||
| Set<String> relatedModelClassNames = getRelatedModelClassNames(index, jpaModel.getAllModelClassNames(), | ||
| modelClassInfo); | ||
|
|
||
| if (modelClassInfo != null && (modelClassInfo.declaredAnnotation(ClassNames.QUARKUS_PERSISTENCE_UNIT) != null | ||
| || modelClassInfo.declaredAnnotation(ClassNames.QUARKUS_PERSISTENCE_UNIT_REPEATABLE_CONTAINER) != null)) { | ||
| modelClassesWithPersistenceUnitAnnotations.add(modelClassInfo.name().toString()); | ||
| Set<String> relatedModelClassNames = new HashSet<>(); | ||
| if (managedClassNames.contains(modelClassName)) { | ||
|
|
||
| ClassInfo modelClassInfo = index.getClassByName(DotName.createSimple(modelClassName)); | ||
| relatedModelClassNames = getRelatedModelClassNames(index, jpaModel.getAllModelClassNames(), | ||
| modelClassInfo); | ||
|
|
||
| if (modelClassInfo != null && (modelClassInfo.declaredAnnotation(ClassNames.QUARKUS_PERSISTENCE_UNIT) != null | ||
| || modelClassInfo | ||
| .declaredAnnotation(ClassNames.QUARKUS_PERSISTENCE_UNIT_REPEATABLE_CONTAINER) != null)) { | ||
| modelClassesWithPersistenceUnitAnnotations.add(modelClassInfo.name().toString()); | ||
| } | ||
| } | ||
|
|
||
| for (Entry<String, Set<String>> packageRuleEntry : packageRules.entrySet()) { | ||
|
|
@@ -1433,7 +1446,8 @@ private static MultiTenancyStrategy getMultiTenancyStrategy(Optional<String> mul | |
| return multiTenancyStrategy; | ||
| } | ||
|
|
||
| private PreGeneratedProxies generateProxies(Set<String> managedClassAndPackageNames, IndexView combinedIndex, | ||
| private PreGeneratedProxies generateProxies(Set<String> managedClassAndPackageNames, Set<String> managedClassesName, | ||
| IndexView combinedIndex, | ||
| TransformedClassesBuildItem transformedClassesBuildItem, | ||
| BuildProducer<GeneratedClassBuildItem> generatedClassBuildItemBuildProducer, | ||
| LiveReloadBuildItem liveReloadBuildItem, | ||
|
|
@@ -1466,6 +1480,12 @@ private PreGeneratedProxies generateProxies(Set<String> managedClassAndPackageNa | |
| CachedProxy proxy = proxyCache.cache.get(managedClassOrPackageName); | ||
| generatedProxyQueue.add(CompletableFuture.completedFuture(proxy)); | ||
| } else { | ||
|
|
||
| if (!managedClassesName.contains(managedClassOrPackageName)) { | ||
| // we don't generate proxies for packages | ||
| continue; | ||
| } | ||
|
|
||
| if (!proxyHelper.isProxiable(combinedIndex.getClassByName(managedClassOrPackageName))) { | ||
| // we need to make sure we have a class and not a package and that it is proxiable | ||
| continue; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package io.quarkus.hibernate.orm.packages; | ||
|
|
||
| import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| import java.util.List; | ||
| import java.util.logging.Level; | ||
|
|
||
| import jakarta.inject.Inject; | ||
| import jakarta.persistence.EntityManager; | ||
| import jakarta.transaction.Transactional; | ||
| import jakarta.transaction.UserTransaction; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
|
||
| import io.quarkus.hibernate.orm.TransactionTestUtils; | ||
| import io.quarkus.test.QuarkusUnitTest; | ||
|
|
||
| public class PackageInfoNonRegressionTest { | ||
|
|
||
| @RegisterExtension | ||
| static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
| .withApplicationRoot((jar) -> jar | ||
| .addClass(TransactionTestUtils.class) | ||
| .addPackage(PackageInfoNonRegressionTest.class.getPackage()) | ||
| .addAsResource("application.properties")) | ||
| .setLogRecordPredicate(record -> record.getLevel().intValue() > Level.WARNING.intValue()) | ||
| .assertLogRecords(logs -> assertThat(logs).noneMatch( | ||
| log -> log.getMessage().contains("ClassLoader QuarkusClassLoader"))); | ||
|
|
||
| @Inject | ||
| EntityManager entityManager; | ||
|
|
||
| @Inject | ||
| UserTransaction transaction; | ||
|
|
||
| @Test | ||
| @Transactional | ||
| public void test() { | ||
|
|
||
| ParentEntity parent1 = new ParentEntity("parent1"); | ||
| entityManager.persist(parent1); | ||
|
|
||
| ParentEntity parent2 = new ParentEntity("parent2"); | ||
| entityManager.persist(parent2); | ||
|
|
||
| List<ParentEntity> entities = entityManager.createQuery("from ParentEntity ", ParentEntity.class).getResultList(); | ||
| assertEquals(2, entities.size()); | ||
|
|
||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.