-
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
Adding projection support for JPASpecificationExecutor
#2499
Comments
That's in place via #2274. We do not want to pollute the API surface with additional overloads that represent all possible combinations of parameter types and operations. |
@mp911de how can we use projection in 'JPASpecification' ? |
The code would look like along the lines of: UserRepository repo;
Specification<User> spec;
List<UserProjection> result = repo.findBy(spec, q -> q.as(UserProjection.class).all()); |
@mp911de I didn't get it. I can't find any |
That's part of the |
Hello, sorry to jump on this thread. I'm trying to implement this, but It seems that the generated SQL is the same of the regular findAll with specification, what makes the use of the projection meaningless. Is there something missing on this code? I should add that I 'm using pagination as well. |
We're attaching a |
The reason it was not working is that my projection was not correctly designed. So it was a error on my side. Thanks for the help. |
Hello @ribertojunior |
Okay I have difficulties with the syntax in Kotlin. Here is my line, abstracted: val result: Page<ItemSearchProjection> = itemRepository.findBy(searchDefinition.specification) { queryFunction -> queryFunction.`as`(
ItemSearchProjection::class.java).page(pageRequest) } This fails for me with There is not enough examples in the usual places like Baeldung or StackOverflow to code by example. [edit] val result: Page<ItemSearchProjection> =
itemRepository.findBy(searchDefinition.specification) { queryFunction: FetchableFluentQuery<Item> ->
queryFunction.`as`(
ItemSearchProjection::class.java
).page(pageRequest)
} But when looking at the Hibernate debug, the resulting DB query still contains all the fields instead of just the ones of the projection interface (and inner interface properties). So if any fetch hints have been given to hibernate, they are proudly ignored. This is with SpringBoot+Data.JPA 3.1.3, Hibernate Core 6.2.7 |
Please ribertojunior show you solution. |
How the query hint can be attached to the method ? Thanks. |
Sorry for taking so long to answer. |
it gives me error |
Hi there,
As per current situation,
JPASpecificationExecutor
does not allowselect
any result other than the entity.Can we allow projection by adding following methods in the
JPASpecificationExecutor
and their implementation insideSimpleJpaRepository
?These methods will allow getting different result type other than
T
where T isJpaSpecificationExecutor<T>
.The text was updated successfully, but these errors were encountered: