The trick how to achive this described in this topic: http://justonjava.blogspot.it/2010/09/lazy-one-to-one-and-one-to-many.html
I've cheched it on Hibernate v.4.3.5 and JPA v.1.5.0, PostgreSQL 9.3. Worked like a charm.
Example:
public class Attachment implements FieldHandled{
@Transient
private FieldHandler fieldHandler;
...
...
@Lob
@Column(name=CONTENT, nullable=false)
@Basic(fetch = FetchType.LAZY, optional = false)
private byte[] content;
...
...
public byte[] getContent() {
if(fieldHandler!=null){
return (byte[])fieldHandler.readObject(this, "content", content);
}
return content;
}
public void setContent(byte[] content) {
if(fieldHandler!=null){
fieldHandler.writeObject(this, "content", this.content, content);
return;
}
this.content = content;
}
}
Note: If you are using CGLib, implement net.sf.cglib.transform.impl.InterceptFieldEnabled instead of FieldHandled, with the same approach.