title: Lazily loading a clob in hibernate
body: <p>There's a lot one can find about this googling a bit but I haven't quite found a workable solution to this problem.</p>
  
  <p>Basically what I have is a big CLOB on a particular class that I want to have loaded on demand. The naive way to do this would be:</p>
  
  <pre><code>class MyType {
  
    // ...
  
    @Basic(fetch=FetchType.LAZY)
    @Lob
    public String getBlob() {
      return blob;
    }
  }
  </code></pre>
  
  <p>That doesn't work though, apparently due to the fact I'm using oracle drivers, i.e. Lob objects aren't treated as simple handles but are always loaded. Or so I've been led to believe from my forays. There is one solution that uses special instrumentation for lazy property loading, but as the Hibernate docs seem to suggest they're less than interested in making that work correctly, so I'd rather not go that route. Especially with having to run an extra compile pass and all.</p>
  
  <p>So the next solution I had envisioned was separating out this object to another type and defining an association. Unfortunately, while the docs give conflicting information, it's apparent to me that lazy loading doesn't work on OneToOne associations with shared primary key. I'd set one side of the association as ManyToOne, but I'm not quite sure how to do this when there's a shared primary key.</p>
  
  <p>So can anybody suggest the best way to go about this?</p>