-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
FluentQuery ignores .project(...)
#3716
Comments
.project()
.project(...)
JPA imposes quite a few limitations. We cannot select only a few properties when returning an entity. While this can work with Hibernate via multiselect and aliased selection items, JPA 3.2 deprecates multiselect and so this approach isn't usable. We provide projection properties to JPA as fetchgraph so that joined properties can be selected/skipped when properties are declared. Technically, we could use projection properties as input properties for DTO and interface projections but from a conceptional perspective, this would for DTO introduce a possibility of defining properties without ensuring that a matching constructor is present. For interface projections, we also select the entire entity (open projection) or selected properties (closed projection) so in both case we would introduce mechanisms that allow breaking functionality. |
Taking a step backward, what do you want to achieve with that setup and what problem are you trying to solve so that we better understand your context. One problem that can emerge from here is a partially hydrated entity that if saved, can wipe database information. I have to admit that the test name is somewhat generalized, it actually tests if relations aren't loaded and not simple properties. |
@mp911de my entity has a property whose value is a large json document. I only want database to return that json property when application queries a single entity. When application queries multiple entities, I want database to not return that json property. The application then projects that entity (without json property) result onto My application calls |
@mp911de List<UserProjectionInterfaceBased> users = repository.findBy(userHasFirstnameLike("v"),
q -> q.as(UserProjectionInterfaceBased.class).sortBy(Sort.by("firstname")).all()); I added |
Hi all,
I downloaded
main
version of spring data (commit sha: 12b5e82)I enabled query logging and run
UserRepositoryTests#findByFluentSpecificationWithSimplePropertyPathsDoesntLoadUnrequestedPaths
test with maven profileshibernate-62
andall-dbs
:In the logs I see the resulting query:
I expect to see only
u1_0.firstname
in the selectThe test queries data with
FluentQuery#project(...)
javadoc says:Define which properties or property paths to include in the query.
The text was updated successfully, but these errors were encountered: