ObjectDB ObjectDB

Detaching objects after JOIN FETCH

#1

Hi,

I have a question about detaching objects after issuing query with JOIN FETCH. Let's say I have two classes:

public class A {

    @ManyToOne

    B bClass

}

public class B {
    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    List<A> aClasses;

}

Now, I want to fetch all B classes with all A classes skipping lazy loading:

select b from B b join fetch b.aClasses

After closing entity manager, B classes became detached but without A classes and because EM is closed, B.aClasses is always null.

I thought, that after join fetch and CascadeType.DETACH list of A classes should be accessible from B, or am I wrong?

edit
delete
#2

You are right. The A instances should be available after detachment in this case.

Could you please provide a test case that demonstrates the problem?

ObjectDB Support
edit
delete
#3

While building test case I get two different cases:

1. When not using mappedBy, like in example above, detached objects are visible even after closing em.

2. When using mappedBy in class B (this is the case in my code), detached objects from relation are not visible.

I should add mappedBy in the example above, but I totally forget about it. Anyway mappedBy shouldn't impact detached objects. I think that both cases should return the same results.

edit
delete
#4

Thank you for this report and for the test case.

The problem was added to the issue tracking system and hopefully will be fixed soon.

Update: The issue is fixed now.

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.