Situation:
Some pseudocode:
@Entity
@Table(name = "table_a")
public class A {
@OneToMany( mappedBy = "aid", cascade = CascadeType.ALL, orphanRemoval = true)
private List<B> listOfBs;
//some code
}
and class B
@Entity
@Table(name = "table_b")
public class B {
public boolean isLocked();
//some code
}
and listener
class DontLoadClosedBsListener implements PostLoadEventListener{
@Override
public void onPostLoad(PostLoadEvent event) {
if(event.getEntity instanceof B){
if(event.getEntity().isLocked()) throw new VeryPeskyException();
}
}
}
The issue is that the listener must stay since it's being used all over the project and too many things depends on that.
My question is: is there any way to tell hibernate to ignore/omit linked entries if there was a problem while reading them?
In other words I want to use my DontLoadClosedBsListener as a filter when working with class A. However I want it to throw an exception when someone will try read locked B outside class A.
Any changes for doing that? Any suggestions?