'Criteria builder sort returns different values with different limits
Hello I have three tables foo, bar and join table foo_bar in between:
public class Foo {
@OneToMany(mappedBy = "foo", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private final List<fooBar> fooBar= new ArrayList<>(); }
public class fooBar{
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "bar_id", nullable = false)
Bar bar;}
public class Bar {
@Column
String name;
}
there are 10 records in foo, 10 in bar, but connected are only 5.
I want all records from foo ordered by name of bar (null values too) so I call the request with sort: foo_bar.bar.name like this:
PageRequest pagerequest = PageRequest.of(0, 4, Sort.by(Sort.Direction.valueOf(ASC), "foo_bar.bar.name"))
fooRepository.findAll( pagerequest);
There are 3 different results:
I call this with start 0 limit 4 and I get total of 10, but only records which are connected (hibernate calls count without any conditions, so total is right)
I call this with start 0 limit 10 and I get total of 5 and I get all the connected records (hibernate DB is called just once, because I get less records than limit)
I call this with different sort (for example Foo.name- "name") or no sort, then I get all records like I want but unsorted
The question is what can I do to change the auto generated where conditions which are automatically generated?
Everything works fine with other sorts so the problem should be in sql generation of this type of hybernate DB request or some setting I did not specify
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
