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

Allow to provide a pre-computed scan PersistenceUnitManager #28287

Closed
snicoll opened this issue Apr 5, 2022 · 5 comments
Closed

Allow to provide a pre-computed scan PersistenceUnitManager #28287

snicoll opened this issue Apr 5, 2022 · 5 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Milestone

Comments

@snicoll
Copy link
Member

snicoll commented Apr 5, 2022

DefaultPersistenceUnitManager is quite classpath-scanning centric. With AOT, we'd like to invoke the scanning of the classpath at build-time and generate a representation of the entities that should be contributed in the PersistenceUnit.

We have a similar problem in Spring Boot with other data stores that is being investigated in spring-projects/spring-boot#30523. The solution there is to have some sort of contract where one implementation is the scanning logic, and another that provides values straight away. I don't know if that would apply here.

The purpose of this issue is to investigate how we could swap this logic when AOT runs so that it uses an hard-coded list, while providing the list to 3rd parties that might need it at build time for further processing

@snicoll snicoll added type: enhancement A general enhancement theme: aot An issue related to Ahead-of-time processing labels Apr 5, 2022
@snicoll snicoll added this to the 6.0.0-M4 milestone Apr 5, 2022
@snicoll
Copy link
Member Author

snicoll commented Apr 5, 2022

I've tried to extract a strategy interface in snicoll@60f7697. I don't have an alternative implementation for the AOT use case but it could be as simple as getting the entities and the mapped resources and provide that back.

It is a bit too magic though as the scope of what the initializer is not clearly specified. I have a feeling that the contract should be changed to produce something else. Maybe an intermediate object that contains the entities and mapped resources?

@snicoll snicoll changed the title Extract classpath scanning logic from DefaultPersistenceUnitManager Allow to provide a pre-computed scan PersistenceUnitManager Apr 6, 2022
@snicoll
Copy link
Member Author

snicoll commented Apr 6, 2022

brainstorming with @jhoeller, we're more aiming towards replacing the DefaultPersistenceUnitManager by an implementation that would know about the scanned entities and mapped resources.

@jhoeller jhoeller added the in: data Issues in data modules (jdbc, orm, oxm, tx) label May 10, 2022
@jhoeller jhoeller self-assigned this May 10, 2022
@jhoeller jhoeller modified the milestones: 6.0.0-M4, 6.0.0-M5 May 12, 2022
@jhoeller jhoeller modified the milestones: 6.0.0-M5, 6.0.0-M6 Jul 8, 2022
@snicoll snicoll self-assigned this Aug 5, 2022
@snicoll
Copy link
Member Author

snicoll commented Aug 5, 2022

So the current plan is to allow AbstractEntityManagerFactoryBean to be "half-initialized" at build-time, preventing the actual EntityManagerFactory to be created. This lets us extract information for the PersistenceUnitInfo and the AOT contributions can be rewritten to use that rather than classpath scanning.

Also, Spring Data can then get the same bean as well, and get the same information to generate their metamodel.

@snicoll
Copy link
Member Author

snicoll commented Aug 5, 2022

95b826b has some initial work for this. It loads the FB and sets the result of the scanning in the AOT-generated bean definition.

#28838 is now a prerequisite for this (in one form or another) as the DataSource is starting up at build-time as well.

snicoll added a commit to snicoll/spring-framework that referenced this issue Aug 18, 2022
@snicoll
Copy link
Member Author

snicoll commented Aug 19, 2022

In the end we extracted the logic of scanning in a dedicated type, PersistenceManagedTypes. This is quite similar to the approach Spring Data took with its ManagedTypes abstraction. The change in public API is minimal and packagesToScan refers to the new facility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants