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

@AfterMapping methods or content mappings may cause BeanCurrentlyInCreationException when the same model type is instantiated as part of the method invocation #375

Closed
olaf-otto opened this issue Jan 29, 2020 · 2 comments

Comments

@olaf-otto
Copy link
Member

@olaf-otto olaf-otto commented Jan 29, 2020

In NEBA 5.1.0, the model and bean lifecycle where consolidated (see e.g. #358). However, the post-processor used to apply the content-to-object mapping was made to do so during the postProcessBeforeInitialization phase, based on the assumption the prototypically scoped Spring beans can be instantiated at will, even if a prototypic bean of type A instantiates another instance of Type A during its initialization.

However, Spring regards this as a programming error. Consequently, Spring models that greedily create another instance of its model type, e.g. Page->Page, will fail when all of the following is true

Spring is used

The instantiation is greedy or in an @AfterMapping method (@AfterMapping is deprecated)

Examples:

@ResourceModel(...)
class MyModel {
    MyModel childPage;
}
@ResourceModel(...)
class MyModel {
    @AfterMapping
    void init() {
       someOtherResource.adaptTo(MyModel.class);
    }
}
@olaf-otto

This comment has been minimized.

Copy link
Member Author

@olaf-otto olaf-otto commented Jan 30, 2020

This problem arises from a fundamental mismatch between the understanding of instantiation semantics within Spring vs. a persistence framework, prototype scope, in Spring, assumes that a single, non-nested instance of a particular bean definition is created as part of the getBean invocation and regards a circular dependency to the same bean definition as a cycle.

persistence frameworks, on the other hand, deal with graphs of objects in which cycles - such as referential relationships - occur naturally.

Thus, the life cycle of content-to-object mapping (where cycles occur) and bean instance creation (where cycles are prohibited) must be separated.

It is thus clear that the implementation of #358 was a mistake and needs to be reverted to the extend that

  1. The bean and model content-to-object mapping lifecycle are separated when using spring and
  2. @AfterMapping must no longer be deprecated.

While NEBA core is unaffected by this issue, semantic consistency demands that @AfterMapping remains available for both spring and non-spring use cases.

olaf-otto added a commit that referenced this issue Jan 30, 2020
…yInCreationException when the same model type is instantiated as part of the method invocation
olaf-otto added a commit that referenced this issue Jan 30, 2020
#375 @AfterMapping methods or content mappings may cause BeanCurrentl…
@olaf-otto

This comment has been minimized.

Copy link
Member Author

@olaf-otto olaf-otto commented Jan 30, 2020

Implemented as described, done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.