I have a table with field byte[] annotated with @Lob = Blob field. This field holds attachments and documentation says that by default it's lazy, so there were no problem with such organization (now I know it's best to have table dedicated for blob). So this field is lazy, but (as i've read) only in Postgres... Oracle doesn't implement lazy for blob fields. So i've read about bytecode instrumentation, i've done ant task and ok - my blob's are lazy. But... my attachments sometimes is getting lost! WTF? Debugging have got an answer: serialization. If blob field is lazy and not loaded, it's null at serialization time and it serializes null. When deserialized, it's still null and hibernate probably is loosing information that it's null because of lazy. So Hibernate see that entity has changed, and with the nearest select it automatically persist it and override blob field with null value. I've tried to lazy load blob field just before serialization, but sometimes entity is disconnected from entity manager and it doesn't work. For now I have an ugly hack: in entity at deserialization time I lookup entity manager via JNDI, find blob field from database and set it manually. Please tell mi how should it work. Because as I see it know it's very serious error which can cause louse of data.
|