Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] How do I batchload many to many relations

In our project we have entity A that has a many to many reference to entity
B. Thousands of A entities normally reference the same B entity.
When I search 1000 A entities and on these use the shared B entity I have
not found a way to avoid fetching the same B entity 1000 times from the
database!
I thought it could be done with batchread but it dosn't seem to work. I have
made a small project to illustrate the problem with an Employee that can
have several Addresses like this:

Employee:
@ManyToMany
    public List<Address> getAddresses() {
        return addresses;
    }

And search for the employees like this:

Query query = em.createQuery("select e from Employee e");
query.setHint("eclipselink.batch", "e.addresses"); 

But the sql send to the database is:

SELECT t1.ID, t1.STREET, t0.Employee_ID FROM EMPLOYEE_ADDRESS t0, EMPLOYEE
t2, ADDRESS t1 WHERE ((t0.Employee_ID = t2.ID) AND (t1.ID = t0.addresses_ID)

which will fetch the address info one time for each employee and then
discard it in the entity manager when it finds out that it already has the
Address loaded.

Is there another way of doing this.

-- 
View this message in context: http://old.nabble.com/How-do-I-batchload-many-to-many-relations-tp26228795p26228795.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top