Search code examples
hibernatejakarta-eeannotations

Is it possible to make @Formula annotation lazily loaded?


I have used @Formula annotation to use it for getting calculated properties. What I need is that those fields/getters which is annotated with @Formula annotation should be lazily loaded.

Is this even possible and if so how?

thanks


Solution

  • Yes . Just annotating the fields/getter of the @Formula property by @Basic(fetch=FetchType.LAZY) and use this ant task provided by hibernate to do the bytecode instrumentation for the entity class. Otherwise , LAZY loading for the @Formula property is silently ignored.

    The documentation contains the info on how to use this ant task to do bytecode instrumentation.