【发布时间】:2010-03-19 15:53:28
【问题描述】:
我想延迟加载 @Lob 属性。 首先,我使用 javassist 来检测我的类,如此处所述http://docs.jboss.org/hibernate/core/3.3/reference/en/html/performance.html#performance-fetching-lazyproperties: 代码:
我的课程包含“摘要”和“标题”属性,它们是 Lob 和其他属性。 代码:
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;
}
.
.
.
}
首先我从数据库中加载一个新闻并想检索新闻的发布日期(我在下面写我的代码) 代码:
newsDAO.findByid(1L).getPublishDate();
findByid 方法是:
Code:
public News findById(Long id) throws ServiceException {
News entity = em.getReference(entityClass, id);
return entity;
}
然后,hibernate 生成这个查询: 代码:
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=?
此查询表明,它不检索 Lob 属性,幸运的是,延迟加载 Lob 属性效果很好。
但是当我只加载新闻的“摘要”属性时 代码:
newsDAO.findByid(1L).getSummary();
然后,hibernate 生成这些查询: 代码:
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=?
我有两个问题: 1.我只想检索“summary”属性而不是“title”属性,但是hibernate查询显示它也检索“title”属性,为什么会这样? 2.为什么hibernate生成两个查询只获取新闻的摘要属性?
如果有人帮助我,我将不胜感激。 科斯罗。
【问题讨论】:
标签: hibernate lazy-loading blob