I try to dump to file full database's contents with the least number of requests.
Thus, How to enable subquery fetching with query.scroll ?
My objects :
I have database like :
Employee (1) ------ (0..n) Address
Employee class :
...
@OneToMany(mappedBy = "employee", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@Fetch(FetchMode.SUBSELECT)
public Set<Address> getAddresses() { ... }
Address class :
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "employee_id", nullable = false)
public Employee getEmployee() { ... }
Java code :
session.createQuery("FROM Employee").scroll(ScrollMode.FORWARD_ONLY);
Expected :
When I use query.find method, I get :
select * from employee
select * from address where employee_id in (select employee_id from employee)
But there are OutOfMemoryError on full database.
And when I use session.scroll, it use batch fetching :
select * from employee
-- and n times :
select * from address where employee_id = ? or employee_id = ? ...
Thus, how can I have "query.find*'s queries with query.scroll
Thanks