I have a spring service with some related entities.
Here's entity A:
@Entity
class A {
@Id
@GeneratedValue(strategy=AUTO)
Long id;
@OneToOne(fetch=LAZY)
@JoinColumn(name = "b_id", referencedColumnName = "id")
B bThing;
}
and entity B:
@Entity
class B {
@Id
@GeneratedValue(strategy=AUTO)
Long id;
String someProperty;
@Basic(fetch=LAZY)
@Column(columnDefinition="BLOB")
@Lob
String wayTooBigThing;
}
Let's say I get a reference to an A from ARepository#findById. Hibernate proxifies the lazy loading for B is as expected, but if I do A.getBThing() at all, it loads the whole B entity, including the lazy large object, which is causing issues.
Is there a way to have lazy loading transitively? I want to be able to do aRepository.findById(x).getBThing().getSomeProperty() without triggering the loading of the large object in B.