-->
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.  [ 3 posts ] 
Author Message
 Post subject: Criteria makes my query returns 0 records
PostPosted: Sat Sep 26, 2009 1:31 pm 
Newbie

Joined: Tue Sep 16, 2008 4:36 am
Posts: 11
Hi everybody,
My problem is quite simple but I have no idea where it comes from.

I am running Hibernate Search within Seam.
here is the code I am running:
Code:
      Session session = ((FullTextHibernateSessionProxy)entityManager.getDelegate()).getSessionFactory().getCurrentSession();
      Criteria searchFilter = session.createCriteria(Request.class);

      LuceneBuilder builder = new LuceneBuilder(searchFilter,Request.class,
            "title","shortDescription","addendum");

      Query q = builder.getQuery(entityManager,query);
      if(from > 0) q.setFirstResult(from);
      if(max > 0) q.setMaxResults(max);
      return q.getResultList();

Where LuceneBuilder does this:
Code:
public Query getQuery(FullTextEntityManager em,String searchText) throws ParseException{
      MultiFieldQueryParser parser = new MultiFieldQueryParser(fields.toArray(new String[0]),new StandardAnalyzer());
      org.apache.lucene.search.Query q = parser.parse(searchText);
      FullTextQuery query = em.createFullTextQuery(q, cls);
      if(criteria != null) query.setCriteriaQuery(criteria);
      return query;
   }



When I try it, it doesn't work.
If I make my criteria null (and then it doesn't set a criteria for the query) it does return a result.

What I don't understand is that the criteria doesn't use any criterion at all, so it shouldn't do a thing. But it doesn't ....
Does someone have any idea why?

Thank you very much in advance.


Here is the Request Class if it can help:
Code:
package com.marroon.webapp.request.model;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import org.hibernate.search.annotations.Analyzer;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;
import org.hibernate.search.annotations.Store;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.NotNull;

import com.marroon.webapp.admin.model.User;
import com.marroon.webapp.common.model.Category;
import com.marroon.webapp.common.model.Location;

@Entity
@Indexed
@Analyzer
public class Request implements Serializable{
   
   /**
    *
    */
   private static final long serialVersionUID = 3195217010000585539L;
   private Long id;
   private User client;
   private Set<Discussion> discussions;
   private Category category;
   private String title;
   private String shortDescription;
   private String addendum;
   private Double budget;
   private Date creationDate;
   private Date lastModificationDate;
   private Date deadline;
   private Location location;
   private String answer;
   private boolean closed;
   private boolean archived;
   
   @Field(store=Store.NO,index=Index.NO)
   public boolean isClosed() {
      return closed;
   }
   public void setClosed(boolean closed) {
      this.closed = closed;
   }
   public boolean isArchived() {
      return archived;
   }
   public void setArchived(boolean archived) {
      this.archived = archived;
   }
   @Id
   @GeneratedValue(strategy=GenerationType.AUTO)
   @DocumentId
   public Long getId() {
      return id;
   }
   public Double getBudget(){
      return this.budget;
   }
   
   @ManyToOne(targetEntity=User.class)
   public User getClient() {
      return client;
   }
   
   @ManyToOne(targetEntity=Category.class)
   public Category getCategory() {
      return category;
   }
   
   @NotNull @NotEmpty
   @Field(index=Index.TOKENIZED,store=Store.NO)
   public String getTitle() {
      return title;
   }
   
   @NotNull @NotEmpty
   @Length(max=2000)
   @Field(index=Index.TOKENIZED,store=Store.NO)
   public String getShortDescription() {
      return shortDescription;
   }
   @ManyToOne(targetEntity=Location.class)
   public Location getLocation(){
      return location;
   }
   
   @Field(index=Index.TOKENIZED,store=Store.NO)
   public String getAddendum() {
      return addendum;
   }

   public Date getCreationDate() {
      return creationDate;
   }
   
   public Date getLastModificationDate() {
      return lastModificationDate;
   }
   
   @OneToMany(mappedBy="request",fetch=FetchType.EAGER,cascade=CascadeType.ALL)
   public Set<Discussion> getDiscussions() {
      return discussions;
   }
   
   public Date getDeadline(){
      return deadline;
   }
   /* SET METHODS */
   public void setId(Long id) {
      this.id = id;
   }
   
   public void setClient(User client) {
      this.client = client;
   }
   public void setCategory(Category category) {
      this.category = category;
   }
   public void setTitle(String title) {
      this.title = title;
   }
   public void setShortDescription(String shortDescription) {
      this.shortDescription = shortDescription;
   }
   public void setAddendum(String addendum) {
      this.addendum = addendum;
   }
   public void setCreationDate(Date creationDate) {
      this.creationDate = creationDate;
   }
   public void setLastModificationDate(Date lastModificationDate) {
      this.lastModificationDate = lastModificationDate;
   }
   public void setDiscussions(Set<Discussion> discussions) {
      this.discussions = discussions;
   }
   public void setLocation(Location location){
      this.location = location;
   }
   public void setBudget(Double budget){
      this.budget = budget;
   }
   public void setDeadline(Date deadline){
      this.deadline = deadline;
   }
   public Request(){}
   
   public Request(User client, Category category,String title, String shortDescription,Double budget,Date deadline, String addendum){
      this.client = client;
      this.category = category;
      this.title = title;
      this.shortDescription = shortDescription;
      this.addendum = addendum;
      this.creationDate = new Date();
      this.lastModificationDate = new Date();
      this.budget = budget;
      this.deadline = deadline;
      this.closed = false;
      this.archived = false;
   }
   @Transient
   public String getAnswer() {
      return answer;
   }
   public void setAnswer(String answer) {
      this.answer = answer;
   }
   @Override
   public String toString() {
      return getTitle();
   }
}


Top
 Profile  
 
 Post subject: Re: Criteria makes my query returns 0 records
PostPosted: Sun Sep 27, 2009 7:16 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
what are you trying to do with this Criteria?
why not:
Code:
FullTextQuery query = em.createFullTextQuery(q, Request.class);

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Criteria makes my query returns 0 records
PostPosted: Sun Sep 27, 2009 9:33 am 
Newbie

Joined: Tue Sep 16, 2008 4:36 am
Posts: 11
I want to do criteria. But it didn't work. So I was looking for a reason why I doesn't return any value.

First thing, I removed all my criteria and checked if it works like this. Apparently it doesn't...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.