-->
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.  [ 4 posts ] 
Author Message
 Post subject: byte array property not lazy loaded!!!
PostPosted: Sat Sep 23, 2006 3:57 pm 
Beginner
Beginner

Joined: Fri Nov 19, 2004 6:41 am
Posts: 39
Location: Stockholm, Sweden
Hello,

I've posted this to the JBoss forum as well without any luck.

http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3973536#3973536.

I'm using JBoss 4.0.4 GA with EJB3.0 RC6 and I'm having problem with a byte array property not being lazy loaded even though it's annotated for lazy loading.

My entity bean is loaded using a EJB-QL statement and the byte array gets loaded even though it's not accessed.

Does anyone know how to fix this? Is it a bug in Hibernate?

My entity bean property is annotated like this:

Code:
@Lob
@Basic(fetch = FetchType.LAZY)
@Column(name = "DOCUMENT", nullable = true)
public byte[] getDocument() {
   return this.document;
}


I'm using the following code to load the entity "Appendix" which have the byte array property.

Code:
// Create traffic type query
final EntityManager theEntityManager = this.getEntityManager();
final Query theTrafficTypeQuery = theEntityManager.createQuery("from Appendix a where a.trafficType = :trafficType");
theTrafficTypeQuery.setParameter("trafficType", theTrafficType);
final List<Appendix> theAppendixes = theTrafficTypeQuery.getResultList();


And the following SQL is produced:

Code:
select appendix0_.APPENDIX_ID as APPENDIX1_0_, appendix0_.START_DATE as START2_0_, appendix0_.DESCRI
PTION as DESCRIPT3_0_,
[b]appendix0_.DOCUMENT as DOCUMENT0_[/b]
, appendix0_.EXTENSION_ID as EXTENSION9_0_, appendix0_.CREATE_DATE as CREATE5_0_, appendix0_.PAGE_ID
as PAGE6_0_, appendix0_.PRODUCT_ID as PRODUCT7_0_, appendix0_.STOP_DATE as STOP8_0_ from APPENDIX a
ppendix0_ where appendix0_.PRODUCT_ID=?


Where the bold part of the query is the byte array property being loaded, but it shouldn't.

Please help me, I'm desperate!!!

Regards, Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 3:11 pm 
Beginner
Beginner

Joined: Fri Nov 19, 2004 6:41 am
Posts: 39
Location: Stockholm, Sweden
Solved it!

Using a java.sql.Blob instead of a byte array.

Though, the JBoss docs says you could have both?!

Anyways, problem has vanished :-)

Cheers!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 26, 2006 4:06 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You need bytecode enhancement to lazy load arrays. A blob JDBC type has lazy loading built in.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 26, 2006 4:43 am 
Beginner
Beginner

Joined: Fri Nov 19, 2004 6:41 am
Posts: 39
Location: Stockholm, Sweden
Yup, I've read it at http://www.hibernate.org/hib_docs/annotations/reference/en/html/entity.html

But I miss the information in the JBoss docs.

Couldn't the code be instrumented if the property isn't a java.sql.Blob and annotated as Lob and lazy by default?

In my simple mind it would be good, but I'm not aware of the million of reasons why it shouldn't.

Seems like a bunch of people have problems with it though...

Thank you Christian for the clearification! :-)

Cheers!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.