Spring, Hibernate, Blob lazy loading

I’m confused. Emmanuel Bernard wrote in ANN-418 that @Lob are lazy by default (i.e. you don’t even need to use the @Basic(fetch = FetchType.LAZY) annotation).

Some users report that lazy loading of a @Lob doesn’t work with all drivers/database.

Some users report that it works when using bytecode instrumentation (javassit? cglib?).

But I can’t find any clear reference of all this in the documentation.

At the end, the recommended workaround is to use a “fake” one-to-one mappings instead of properties. Remove the LOB fields from your existing class, create new classes referring to the same table, same primary key, and only the necessary LOB fields as properties. Specify the mappings as one-to-one, fetch=”select”, lazy=”true”. So long as your parent object is still in your session, you should get exactly what you want. (just transpose this to annotations).

Leave a Comment