-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Provide more control over JPA entities scanning #27892
Comments
See spring-projects/spring-boot#29193 (comment) for background information on the proposal. |
If we specify the classes explicitly, it's not really scanning anymore, isn't it? That rather looks like a way to provide the list of entity classes rather than creating the persistence unit manually. That could be interesting with AOT where the regular scanning can happen at build-time. |
Hi, the main purpose for suggesting this, is that sometimes during development, we might want to temporarily turn off scanning all entities except for a few ones, so that our development can concentrate on just a few entities first. E.g I just want to concentrate on entity A, B, C , while the remaining entities might still be unfinished, and might cause errors during boot up, if they are scanned. To me, scanning list of entity classes is still considered "scan". I use this term "scan" as it align with spring's component scanning feature where it also support scanning by classess. |
This is a bit like the EnableFeignClients annotation, if clients are not provided, use package scanning, otherwise use the provided ones |
I agree with the clarification that entities scan should be package scan based.
Case 1:
Case 2
You can come up with your own organization; either way, good practice suggest that your entities should be grouped by package. |
Hi,
Perhaps, one might propose why not i resolve the issues for ALL the entities once and for all, before i start verifying the pages. Sure, but at the end, it still boiled down to individual developers preference, and resolving all entities first, before verifying the pages might not always be feasible thing to do . There is no right or wrong. Different developers have their own adapted ways for handling my above-mentioned scenarios. One might also suggest, why not temporarily move these 4 problematic entities classes out of the scanned package. Sure, that works. But if we have a simpler way of doing things (scanning for specific classes configuration), why not? no one likes to move the entities in and out of the scanned package again and again... There are definitely valid scenario to justify why we need such feature, that is why online research tells that I am not the only one looking for such feature . In fact, I was also suggesting to be able to exclude scan for specific classess e.g @EntityScan(excludeClassess="MyClass1", so that all classess are scanned except for the listed ones. |
I'm not convinced that selecting individual entity classes (instead of scanning the package) is worthwhile, but I can foresee it being useful to be able to exclude particular classes based on a filter. That's also what @wilkinsona suggested in spring-projects/spring-boot#29193 (comment). Note that |
I support the idea of exclude based on filter, as it is more flexible. |
Even though i support the idea of exclude on filter, but why not make it more complete by also giving the ability to include only specific ones. To cater for a wide range of developers. |
We have a prototype ready to be investigated by the Spring Boot team and we can then merge accordingly. |
Hi,
I would like to request for
@EntityScan
to be able to provide the ability to scan for specific entities class, rather than based on package. E.g@EntityScan(classes={"com.aa.ClassA", "com.aa.ClassB"))
will only scan for these 2 classes and other classes in the same package will NOT be scan.Searching internet shows many people asking for such capabilities and end up having to write some codes to circumvent this.
Adding such capabilities made life easy for developers
Likewise, should also provide similar way to configure this in properties/yaml as well.
E.g
spring.jpa.entity-scan-classes=com.aa.ClassA,com.aa.ClassB
The text was updated successfully, but these errors were encountered: