views:

437

answers:

1

I have JPA entity (Object A) with a One-Many owning relationship (Object B) in an ArrayList.

I want to be able to query (either Hibernate or JPA) for Object A without having any of the instances of association Object B returned (no proxies or otherwise) in the One-Many ArrayList.

Ideally the returned ArrayList would be null or empty.

Is this possible? In rough pseudocode this is what I want:

"from ObjectA where ObjectA.id=5 DO NOT INCLUDE ObjectB"

or

"Select a from ObjectA a FETCH IGNORE a.ObjectBs where a.id=5"

+1  A: 

If the association for ObjectBs in ObjectA is lazy, ObjectBs won't be returned with your query unless your query specifies to fetch them.

If you were to access any ObjectBs once your session is closed, you would get a LazyInitializationException because your ObjectBs were not loaded into memory.

jedierikb