Hello,
I want to lazy load of @Lob properties.I first try using CGLIB but as i described here
https://forum.hibernate.org/viewtopic.php?f=1&t=1003331 i got exception and it seems no one can help me. So then i try javassist.
First ,i use javassist and using the following Ant task to instrument my class:
Code:
<project name="Samples" default="testAll" basedir=".">
<property name="librarydir" value="${basedir}/lib"/>
<path id="libraries">
<fileset dir="${librarydir}">
<include name="*.jar"/>
</fileset>
</path>
<target name="instrument">
<taskdef name="instrument"
classname="org.hibernate.tool.instrument.javassist.InstrumentTask"
classpathref="libraries"/>
<instrument verbose="true">
<fileset dir="${basedir}">
<include name="Post.class"/>
<include name="News.class"/>
</fileset>
</instrument>
</target>
</project>
My class contains "summary" and "title" properties those are Lob and other properties.
Code:
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;
}
.
.
.
}
First i load one news from database and want to retrieve publishdate of news(i write my codes in below)
Code:
newsDAO.findByid(1L).getPublishDate();
and findByid method is :
Code:
public News findById(Long id) throws ServiceException {
News entity = em.getReference(entityClass, id);
return entity;
}
then ,hibernate generates this query:
Code:
Hibernate:
select
news0_.id as id1_,
news0_.entityVersion as entityVe2_1_,
news0_.publishDate as publish15_1_,
news0_.url as url1_
from
News news0_
where
news_.id=?
This query shows that ,it does not retrieve Lob property and fortunately lazy loading of Lob properties works well.
But when i load only "summary" property of news
Code:
newsDAO.findByid(1L).getSummary();
then ,hibernate generates these queries:
Code:
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 query shows that it also retrieve "title" property,Why this happens?
2.Why hibernate generates two query for retrieving only summary property of news?
I would be appreciate if anyone helps me.
Khosro.