Home How to force hibernate not to load subentities
Reply: 0

How to force hibernate not to load subentities

user903 Published in April 22, 2018, 12:36 am

I have A and B entities where A can have more Bs

@Table(name = "A")
public class A {

@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "b_id", nullable = false, insertable = true, updatable = false)
private Set<B> bs;


what I need is to say jpa somehow not to load set of Bs in special situations.

I tried it other way around, I defined fetch = FetchType.Lazy and then I say hibernate when i want to load B. Problem is however, that when i do a.getBs(), hibernate loads the bs even when i dont want this behaviour ( I wanted only check if B is loaded or not). It means I need to force hibernate with jpa not to load subentities later (a.getBs()) with lazy load mode OR to force not to load entities with eager load mode.

In jpa there is method Root.fetch(). I would need Root.unfetch()

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304616 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO