You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am upgrading my company applications to spring boot 2.6.6, which includes spring-data-commons 2.6.3.
Doing that, I bumped into this problem: spring-projects/spring-data-rest#2095.
This problem was supposed to be fixed in 2.6.1 version but I am still experiencing it, and after a long debugging journey I might have found the problem.
public PersistentEntity<?, ? extends PersistentProperty<?>> getRequiredPersistentEntity(Class<?> type) {
Assert.notNull(type, "Domain type must not be null!");
if (contexts.size() == 1) {
return contexts.iterator().next().getRequiredPersistentEntity(type);
}
return getPersistentEntity(type).orElseThrow(() -> {
return new MappingException(String.format(
"Cannot get or create PersistentEntity for type %s! PersistentEntities knows about %s MappingContext instances and therefore cannot identify a single responsible one. Please configure the initialEntitySet through an entity scan using the base package in your configuration to pre initialize contexts.",
type.getName(), contexts.size()));
});
}
When there's a single mapping context, an optimization is done to invoke getRequiredPersistentEntity on that single one.
That works well with the solution made in the other issue reported, a proxy class for an entity is correctly related to its concrete class and everything works fine.
However, when we have multiple contexts, we dive into this method:
public Optional<PersistentEntity<?, ? extends PersistentProperty<?>>> getPersistentEntity(Class<?> type) {
for (MappingContext<?, ? extends PersistentProperty<?>> context : contexts) {
if (context.hasPersistentEntityFor(type)) {
return Optional.of(context.getRequiredPersistentEntity(type));
}
}
return Optional.empty();
}
In here, before invoking getRequiredPersistentEntity, it's being called hasPersistentEntityFor with the class being a HibernateProxy.
I am not sure why - but hasPersistentEntityFor is returning false in that situation, preventing the subsequent method to be called.
The other contexts I have are unrelated so they are expected to return false.
Looking at the caller method, this causes an exception that prevents the completion of the request.
But when a single context is involved, no issue happens.
I am attaching 2 simple spring-boot applications that reproduce the inconsistency. One with a single context, one with more than one. single context multiple contexts
For both, the problem is reproduced by using the following cURL command:
curl --location --request GET 'localhost:8088/api/test/userGroups?projection=projection'
Using the single-context app, no error will happen. In the multi-context, the error will happen.
I appreciate the time and if you guys are able to look into this please.
Our upgrade to latest spring boot is now blocked.
Hello,
I am upgrading my company applications to spring boot 2.6.6, which includes spring-data-commons 2.6.3.
Doing that, I bumped into this problem: spring-projects/spring-data-rest#2095.
This problem was supposed to be fixed in 2.6.1 version but I am still experiencing it, and after a long debugging journey I might have found the problem.
The inconsistency I found lives in here:
When there's a single mapping context, an optimization is done to invoke
getRequiredPersistentEntity
on that single one.That works well with the solution made in the other issue reported, a proxy class for an entity is correctly related to its concrete class and everything works fine.
However, when we have multiple contexts, we dive into this method:
In here, before invoking
getRequiredPersistentEntity
, it's being calledhasPersistentEntityFor
with the class being a HibernateProxy.I am not sure why - but
hasPersistentEntityFor
is returning false in that situation, preventing the subsequent method to be called.The other contexts I have are unrelated so they are expected to return false.
Looking at the caller method, this causes an exception that prevents the completion of the request.
But when a single context is involved, no issue happens.
I am attaching 2 simple spring-boot applications that reproduce the inconsistency. One with a single context, one with more than one.
single context
multiple contexts
For both, the problem is reproduced by using the following cURL command:
Using the single-context app, no error will happen. In the multi-context, the error will happen.
I appreciate the time and if you guys are able to look into this please.
Our upgrade to latest spring boot is now blocked.
Thanks
Joao
[email protected]
The text was updated successfully, but these errors were encountered: