-->
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.  [ 1 post ] 
Author Message
 Post subject: Lazy loading of Lob property with javassist
PostPosted: Thu Mar 18, 2010 3:18 pm 
Newbie

Joined: Fri Jan 22, 2010 1:51 pm
Posts: 4
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.


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

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.