Lazy loading of Blob properties of one class
Posted
by Khosro
on Stack Overflow
See other posts from Stack Overflow
or by Khosro
Published on 2010-03-19T15:53:28Z
Indexed on
2010/03/19
16:21 UTC
Read the original article
Hit count: 544
Hi, My class contains "summary" and "title" properties those are Blob and other properties. Code:(I write some part of class)
public class News extends BaseEntity{
@Lob
@Basic(fetch = FetchType.LAZY)
public String getSummary() {
return summary;
}
@Lob
@Basic(fetch = FetchType.LAZY)
public String getTitle() {
return title;
}
@Temporal(TemporalType.TIMESTAMP)
public Date getPublishDate() {
return publishDate;
}
}
I instrument this class to lazy load of Blob properties using this class "org.hibernate.tool.instrument.javassist.InstrumentTask".When i write this code to retrieve only summary of new ,
newsDAO.findByid(1L).getSummary();
Hibernate generates these queries:
Hibernate:
select
news0_.id as id1_,
news0_.entityVersion as entityVe2_1_,
news0_.publishDate as publish15_1_,
news0_.url as url1_
from
News news0_
Hibernate:
select
news_.summary as summary1_,
news_.title as title1_
from
News news_
where
news_.id=?
I have two qurestions:1.I only want to retrieve "summary" property not "title" property,but Hibernate queries show that it also retrieve "title" property,Why this happens(i want to lazy load of "property")? It seems when i load one of Blob property ,Hibernate loads all of them.Why?(This is my main question)
2.Why Hibernate generates two queries for retrieving only "summary" property of news?
Khosro.
© Stack Overflow or respective owner