-->
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: Hibernate Search - store=Store.YES and db access
PostPosted: Fri Sep 26, 2008 2:46 am 
Newbie

Joined: Fri Sep 26, 2008 1:44 am
Posts: 5
Hibernate Search version: 3.0.1 GA

Name and version of the database you are using: HSQLDB

Hi , I am very new to Hibernate and Hibernate Search.

I read this article http://www.javaworld.com/javaworld/jw-0 ... tml?page=1

In this article the author has mentioned

Quote:
The attribute store=Store.NO indicates that the actual data (that is, the Word documents) will not be stored in the index; therefore, that bean property will be returned through a separate SQL query as part of the Hibernate full-text search that returns the Resume entity objects. In contrast, if I had set store=Store.YES, the original Word documents would have been stored in and retrieved from the index without any database access.


Problem/Question: I have specified all my attributes/object member variables as store=Store.YES, but still I see an extra query that is sent to the DB . Is this an expected behavior ?. or the author is wrong ?. Other than this EVERYTHING is working FINE.(my search results are as expected). I am worried about that extra DB query.


I am having a model object called SearchObject and using XDoclet to generate the mapping XML and java annotations for Hibernate search

Code:
@Indexed
public class SearchObject implements Serializable {
   
   @DocumentId
   private Long id;
   @Field(index=Index.TOKENIZED, store=Store.YES)
   private String body;
   @Field(index=Index.UN_TOKENIZED, store=Store.YES)
   @DateBridge(resolution=Resolution.DAY)
   private Date createdDate;
   /**
    * @return the id
    * @hibernate.id
    * column="SEARCH_OBJECT_ID"
    * unsaved-value="null"
    * generator-class="native"
    *
    */
   public Long getId() {
      return id;
   }
   /**
    * @param id the id to set
    */
   public void setId(Long id) {
      this.id = id;
   }
   /**
    * @return the body
    * @hibernate.property
    * column="BODY_TEXT"
    * length="600"
    */
   public String getBody() {
      return body;
   }
   /**
    * @param body the body to set
    */
   public void setBody(String body) {
      this.body = body;
   }
   /**
    * @return the createdDate
    * @hibernate.property
    * column="CREATED_DATE"
    */
   public Date getCreatedDate() {
      return createdDate;
   }
   /**
    * @param createdDate the createdDate to set
    */
   public void setCreatedDate(Date createdDate) {
      this.createdDate = createdDate;
   }
   
}


I am using Spring's Hibernate template to save this object

Code:
   public void save(SearchObject searchObject) {
      getHibernateTemplate().saveOrUpdate(searchObject);
   }


I have this search method in DAO

Code:
   @SuppressWarnings(value = "unchecked")
   public List<Object[]> search(final String searchString){
      return (List<Object[]>) getHibernateTemplate().execute(
               new HibernateCallback() {
   
                  /* (non-Javadoc)
                   * @see org.springframework.orm.hibernate3.HibernateCallback#doInHibernate(org.hibernate.Session)
                   */
                  public Object doInHibernate(Session session)
                        throws HibernateException, SQLException {
                     try {
                     FullTextSession fullTextSession = Search.createFullTextSession(session);
                     QueryParser parser = new MultiFieldQueryParser(new String[]{"body"}, new StandardAnalyzer());
                     Query query = parser.parse(searchString);
                     //org.hibernate.Query hibernateQuery = fullTextSession.createFullTextQuery(query, SearchObject.class);
                     FullTextQuery hibernateQuery = fullTextSession.createFullTextQuery(query, SearchObject.class);
                     return hibernateQuery.list();
                     } catch (ParseException pexc) {
                        throw new HibernateException(pexc);
                     }
                  }
                  
               }
      );
   }


This is the insert query and the EXTRA search query to DB

Code:
[@APPNAME@] DEBUG [http-8484-Processor24] SQL.log(401) | insert into SEARCH_OBJ (SEARCH_OBJECT_ID, BODY_TEXT, CREATED_DATE) values (null, ?, ?)
Hibernate: insert into SEARCH_OBJ (SEARCH_OBJECT_ID, BODY_TEXT, CREATED_DATE) values (null, ?, ?)
[@APPNAME@] DEBUG [http-8484-Processor24] SQL.log(401) | call identity()
Hibernate: call identity()
[b][@APPNAME@] DEBUG [http-8484-Processor24] SQL.log(401) | select this_.SEARCH_OBJECT_ID as SEARCH1_8_0_, this_.BODY_TEXT as BODY2_8_0_, this_.CREATED_DATE as CREATED3_8_0_ from SEARCH_OBJ this_ where (this_.SEARCH_OBJECT_ID in (?, ?, ?, ?, ?))
Hibernate: select this_.SEARCH_OBJECT_ID as SEARCH1_8_0_, this_.BODY_TEXT as BODY2_8_0_, this_.CREATED_DATE as CREATED3_8_0_ from SEARCH_OBJ this_ where (this_.SEARCH_OBJECT_ID in (?, ?, ?, ?, ?))[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 26, 2008 6:05 pm 
Newbie

Joined: Fri Sep 26, 2008 1:44 am
Posts: 5
Hi ,

Is there any update on this ? Am I missing some annotations or settings that tells Hibernate search to build the object state from existing Lucene Index (just like when we use projection). Or will there be an extra query to the DB using lucene documentID.

Thanks in advance
Reets


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2008 8:34 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I just read the article. Regarding Store.YES it is just wrong.

Hibernate Search will per default query the Lucene index to determine the ids of the matching entities. It then uses the entity ids to retrieve these matching entities from the db. This is the query you are seeing.

If you want to bypass the db completely you have to use projections - http://www.hibernate.org/hib_docs/search/reference/en/html_single/#projections. However, you are then working with object arrays instead of managed objects.

If you want to know more have a look through the online documentation, or even better get hold of a copy of "Hibernate Search in Action".

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2008 5:06 am 
Newbie

Joined: Fri Sep 26, 2008 1:44 am
Posts: 5
Thanks for the reply..


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.