I am using Hibernate with Kotlin and I am having an issue with FetchType.LAZY on @ManyToOne relations. Consider following:
@ManyToOne(fetch = FetchType.LAZY)
open var event: Event?
The problem is that when FetchType.LAZY is used, the fetched Event will be of class Event_$$_jvst_... with JavaassistLazyInitializer on it. But the event will never be initialized, everything will be null or empty.
- Once the
FetchType.LAZYis removed, everything works correctly. - This didn't happen in Java.
- I tried to add
openon thevarso that theEventcan be correctly proxied. No effect. - All the
@Entityclasses are of courseopenas well. If theopenkeyword is removed, there will be no proxy created and so no laziness.
My guess is that Hibernate cannot easily proxy these default kotlin getters. Is there a way to solve it?