0

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

1 Answers1

0

I tried something : create 2 ScrollResult and mapped relations by myself, replacing hibernate's PersistentSet.

It's work ! But I'm not sure it's a good practice ... And it take lot of database's temporary memory.

Any advise on this practice ?