Skip to content
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

Parent type being reported in case of invalid field #9

Closed
mhewedy opened this issue Apr 23, 2021 · 3 comments
Closed

Parent type being reported in case of invalid field #9

mhewedy opened this issue Apr 23, 2021 · 3 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@mhewedy
Copy link
Owner

mhewedy commented Apr 23, 2021

Actual:
Unable to locate Attribute with the the given name [invalidFieldName] on this ManagedType [com.github.mhewedy.expressions.Auditable]
Expected:
Unable to locate Attribute with the the given name [invalidFieldName] on this ManagedType [com.github.mhewedy.expressions.Employee]

full stack trace:

2021-04-23 04:47:06.553  INFO 42381 --- [           main] o.s.t.c.transaction.TransactionContext   : Rolled back transaction for test: [DefaultTestContext@524d6d96 testClass = ExpressionsRepositoryImplTest, testInstance = com.github.mhewedy.expressions.ExpressionsRepositoryImplTest@11bd0f3b, testMethod = testInvalidFieldName@ExpressionsRepositoryImplTest, testException = java.lang.AssertionError: 
Expecting:
 <"Unable to locate Attribute  with the the given name [invalidFieldName] on this ManagedType [com.github.mhewedy.expressions.Auditable]; nested exception is java.lang.IllegalArgumentException: Unable to locate Attribute  with the the given name [invalidFieldName] on this ManagedType [com.github.mhewedy.expressions.Auditable]">
to contain:
 <"ManagedType [com.github.mhewedy.expressions.Employee]"> , mergedContextConfiguration = [MergedContextConfiguration@152aa092 testClass = ExpressionsRepositoryImplTest, locations = '{}', classes = '{class org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration, class org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper=true}', contextCustomizers = set[[ImportsContextCustomizer@44a7bfbc key = [@org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureDataJpa(), @org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureTestEntityManager(), @org.springframework.data.jpa.repository.config.EnableJpaRepositories(repositoryBaseClass=class com.github.mhewedy.expressions.ExpressionsRepositoryImpl, enableDefaultTransactions=true, excludeFilters=[], basePackageClasses=[], escapeCharacter=\, includeFilters=[], bootstrapMode=DEFAULT, repositoryFactoryBeanClass=class org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean, queryLookupStrategy=CREATE_IF_NOT_FOUND, entityManagerFactoryRef=entityManagerFactory, namedQueriesLocation=, transactionManagerRef=transactionManager, basePackages=[com.github.mhewedy.expressions], repositoryImplementationPostfix=Impl, considerNestedRepositories=false, value=[]), @org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase(replace=ANY, connection=NONE), @org.apiguardian.api.API(consumers=[*], since=5.0, status=STABLE), @org.springframework.boot.test.autoconfigure.core.AutoConfigureCache(cacheProvider=NONE), @org.springframework.boot.autoconfigure.domain.EntityScan(basePackages=[], value=[com.github.mhewedy.expressions], basePackageClasses=[]), @org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters(value=[class org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTypeExcludeFilter]), @org.springframework.context.annotation.Import(value=[class org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelector]), @org.springframework.test.context.ContextConfiguration(inheritInitializers=true, initializers=[], loader=interface org.springframework.test.context.ContextLoader, classes=[class org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration, class org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration], name=, locations=[], value=[], inheritLocations=true), @org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase(replace=ANY, connection=H2), @org.springframework.transaction.annotation.Transactional(propagation=REQUIRED, rollbackForClassName=[], transactionManager=, isolation=DEFAULT, timeoutString=, readOnly=false, label=[], noRollbackFor=[], noRollbackForClassName=[], value=, timeout=-1, rollbackFor=[]), @org.springframework.boot.autoconfigure.ImportAutoConfiguration(value=[], exclude=[], classes=[]), @org.junit.jupiter.api.extension.ExtendWith(value=[class org.springframework.test.context.junit.jupiter.SpringExtension]), @org.springframework.context.annotation.Import(value=[class org.springframework.boot.autoconfigure.domain.EntityScanPackages$Registrar]), @org.springframework.test.context.BootstrapWith(value=class org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper), @org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration(enabled=false), @org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest(bootstrapMode=DEFAULT, useDefaultFilters=true, excludeFilters=[], showSql=true, excludeAutoConfiguration=[], includeFilters=[], properties=[]), @org.springframework.boot.test.autoconfigure.properties.PropertyMapping(value=spring.test.database, skip=NO), @org.springframework.context.annotation.Import(value=[class org.springframework.data.jpa.repository.config.JpaRepositoriesRegistrar])]], org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@175c2241, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@776aec5c, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory$DisableAutoConfigurationContextCustomizer@4c12331b, org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@1573f9fc, org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizer@351584c0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@d646b630, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@489115ef, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@0], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.event.ApplicationEventsTestExecutionListener.recordApplicationEvents' -> false]]

java.lang.AssertionError: 
Expecting:
 <"Unable to locate Attribute  with the the given name [invalidFieldName] on this ManagedType [com.github.mhewedy.expressions.Auditable]; nested exception is java.lang.IllegalArgumentException: Unable to locate Attribute  with the the given name [invalidFieldName] on this ManagedType [com.github.mhewedy.expressions.Auditable]">
to contain:
 <"ManagedType [com.github.mhewedy.expressions.Employee]"> 

	at com.github.mhewedy.expressions.ExpressionsRepositoryImplTest.testInvalidFieldName(ExpressionsRepositoryImplTest.java:277)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

mhewedy added a commit that referenced this issue Apr 23, 2021
@mhewedy mhewedy added this to the 0.0.3 milestone Apr 23, 2021
@mhewedy
Copy link
Owner Author

mhewedy commented Apr 23, 2021

The issue related to:

org.hibernate.metamodel.model.domain.internal.checkNotNull

@mhewedy
Copy link
Owner Author

mhewedy commented Apr 23, 2021

image

according to the debug session above, (from class org.hibernate.metamodel.model.domain.internal.AbstractManagedType),
the getAttribute method tries to get attributes from the current class, and if not find, will try to get attribute from the parent class. and if not found, will report the problem on the parent class itself.

@mhewedy
Copy link
Owner Author

mhewedy commented Apr 23, 2021

Suggested solutions:

  1. use hibernate extension findAttribute() that return the attribute or null
  2. catch the exception when calling type.getAttribute(name) and report it in a more clear way

I would go with option 2, as option 1 will make the library less portable.

@mhewedy mhewedy added the enhancement New feature or request label Apr 23, 2021
mhewedy added a commit that referenced this issue Apr 24, 2021
@mhewedy mhewedy self-assigned this Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant