-
Notifications
You must be signed in to change notification settings - Fork 150
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
[BUG] JoinFetch alias while pagination #138
Comments
The minimal code which reproduces the bug: ( import net.kaczmarzyk.E2eTestBase;
import net.kaczmarzyk.spring.data.jpa.Customer;
import net.kaczmarzyk.spring.data.jpa.CustomerRepository;
import net.kaczmarzyk.spring.data.jpa.domain.In;
import net.kaczmarzyk.spring.data.jpa.web.annotation.JoinFetch;
import net.kaczmarzyk.spring.data.jpa.web.annotation.Spec;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
public class Issue138 extends E2eTestBase {
@RestController
public static class TestControllerIssue138 {
@Autowired
private CustomerRepository customerRepository;
@RequestMapping(value = "/issue138/join-fetch-interface/customers", params = { "orderIn" })
@ResponseBody
public Object findByOrderIn(@JoinFetch(paths = "orders", alias = "o")
@Spec(path = "o.itemName", params = "orderIn", spec = In.class) Specification<Customer> spec, Pageable pageable) {
return customerRepository.findAll(spec, pageable);
}
}
@Test
public void resolveSpecBasedOnJoinFetchAliasForPagedRequest() throws Exception {
mockMvc.perform(get("/issue138/join-fetch-interface/customers")
.param("orderIn", "Pizza")
.param("order", "Duff Beer")
.param("page", "0")
.param("size", "1")
.param("sort", "id")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$").isArray())
.andExpect(jsonPath("$[0].firstName").value("Homer"))
.andExpect(jsonPath("$[1]").doesNotExist());
}
} |
@yarikwest Thanks for reporting. After short analysis I understand the issue and prepared a working PoC of a fix. But it needs more testing and refactoring. In a nuthshell:
I think this is the way to go, but:
So it requires more work. You can compiling the version from the branch and see if it solves your issue in the meantime |
(Marking as good first issue because sb could at least write more tests e.g. with nested joins (i.e. join fetching on a joined entity). The actual implementation requires more deep knowledge of the internals) |
(uploaded as 2.9.1-SNAPSHOT to my private Maven repo for easier evaluation, see bottom of the README for the location details) |
@yarikwest fix included in v2.10.0 (just released) |
Hi.
First of all, thanks for great library.
I have found bug while creating query with JoinFetch and filtering by fetched entity. Select query is ok, but when using pagination and results is more than page size, then count query (where is bug) also gets created, and it doesn't contain join.
Example:
Generated sql:
Exception:
But when using like this, than everything ok:
And generated count query looks like this:
The text was updated successfully, but these errors were encountered: