These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Lazy-loading a Lob
PostPosted: Wed Nov 10, 2010 2:53 pm 
Newbie

Joined: Wed Nov 10, 2010 2:28 pm
Posts: 2
Hello,

I crawled hours now through the net searching a solution, so I finally ask you my question:

I've got a class files which contains a clob. Well it's a clob and clobs are used for large data, so I don't want to load it right with the files, if I'll only get an overview of them.

Code:
@Entity
@Table(name = "FILES")
public class File implements Serializable {

   @Id
   @Column(name = "ID")
   private int id;

   @Lob
   @Column(name = "DATA")
   @Basic(fetch = FetchType.LAZY)
   private char[] data;

   // ...
   // getter and setter
   // ...

}


Usually, i'd expect from Hibernate, that it will load the clob, when I first access it.
Selecting a Lob with JDBC, you also only get a reference, from which you can load the data with a stream.

But with some reason, this doesn't work directl with Hibernate, as I had to read.
In the documentation I read something of a "Bytecode Instrumentation".
Sadly I don't have a clue what this is.. so what it es, why it is needed, nor a tutorial or example how it's inserted.

I have to add that i work with Eclipse.

So i would really really be happy, if someone could tell me how the thing works :).
I don't get a point to start with.

Thanks in advance!


Top
 Profile  
 
 Post subject: Re: Lazy-loading a Lob
PostPosted: Thu Nov 11, 2010 7:37 am 
Senior
Senior

Joined: Fri Oct 08, 2010 8:44 am
Posts: 130
Try to set "hibernate.bytecode.use_reflection_optimizer" system property to "false".


Top
 Profile  
 
 Post subject: Re: Lazy-loading a Lob
PostPosted: Fri Nov 12, 2010 6:10 am 
Regular
Regular

Joined: Thu May 07, 2009 5:56 am
Posts: 94
Location: Toulouse, France
fyaa wrote:
But with some reason, this doesn't work directl with Hibernate, as I had to read.
In the documentation I read something of a "Bytecode Instrumentation".

Hibernate uses a runtime proxy generation to provide lazy loading and this works only for entity associations and collections. if you want to load an individual scalar property you must use a build time bytecode instrumentation (lazy loading with interception)

You can also replace your char[] field by java.sql.Blob (or Clob), according to Hibernate the driver implementation of Blob and Clob provide lazy loading by definition (but i've encountered a lot of problems with PostgreSQL and MySQL databases. see viewtopic.php?f=1&t=1006742 and viewtopic.php?f=1&t=1005584)

fyaa wrote:
Sadly I don't have a clue what this is.. so what it es, why it is needed, nor a tutorial or example how it's inserted.

to enable interception, the bytecode of your classes must be instrumented after compilation like shown here viewtopic.php?f=1&t=1005893

_________________
everything should be made as simple as possible, but not simpler (AE)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.