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]