-->
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: Hibernate Search in JBoss returning no results
PostPosted: Fri May 18, 2007 3:51 am 
Newbie

Joined: Fri May 18, 2007 3:37 am
Posts: 2
Hibernate Search Version: 3.0.0 Beta 1
JBOss Version: 4.0.5 GA

I have a POJO
Code:
@Entity
@Table(name = "test")
@Indexed
public class User implements Serializable{
   
   int testId;
   String firstName;
   
   
   String lastName;
   
   public User()
   {
      
   }
   public User(String fname, String lname){
      this.firstName = fname;
      this.lastName = lname;
   }
   
   @Column(name = "FirstName")
   public String getFirstname() {
      return firstName;
   }
   
   
   public void setFirstname(String firstname) {
      this.firstName = firstname;
   }
   
   @Column(name = "LastName")
   @Field(name="lastname", index = Index.TOKENIZED)
   public String getLastname() {
      return lastName;
   }
   
   
   public void setLastname(String lastname) {
      this.lastName = lastname;
   }
   
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @Column(name = "TestId")
   @DocumentId
   public int getTestid() {
      return testId;
   }
   
   public void setTestid(int id){
      this.testId = id;
   }
}


and this code in a Session bean running in JBoss. I have been able to insert data into MySQL 5.0 using this POJO but my Hibernate Search query returns no results even when there are rows in the table

Code:
AnnotationConfiguration cfg = new AnnotationConfiguration();
      cfg.setProperty("hibernate.search.default.directory_provider", RAMDirectoryProvider.class.getName());
      cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
      cfg.addPackage("");
      cfg.addAnnotatedClass(User.class);
      cfg.setProperty("hibernate.dialect","org.hibernate.dialect.MySQLDialect" );
      cfg.setProperty("hibernate.connection.password","kanpur" );
      cfg.setProperty("hibernate.connection.username","root" );
      cfg.setProperty("hibernate.connection.driver_class","com.mysql.jdbc.Driver");
      cfg.setProperty("hibernate.connection.url","jdbc:mysql://localhost:3306/test" );

      org.hibernate.search.event.FullTextIndexEventListener listener = new org.hibernate.search.event.FullTextIndexEventListener();
      cfg.setListener("post-update", listener);
      cfg.setListener("post-insert", listener);
      cfg.setListener("post-delete", listener);
      SessionFactory sessionFactory = cfg.buildSessionFactory();
      
      Session session = sessionFactory.openSession();
      FullTextSession fullTextSession = Search.createFullTextSession(session);
      QueryParser parser = new QueryParser("lastname", new StandardAnalyzer());
      try {
      Query query = parser.parse("lastname:Lalwani");
      List result = fullTextSession.createFullTextQuery(query,User.class).list();
      System.out.println(result.size());
      
      }catch(Exception e){e.printStackTrace();}


What am i doing wrong? Any help will be would be great.

Thanks
yll


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 10:37 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you need to index your data before searching it.
And since you use the RAMirectoryProvider, you need to reindex it each time you start your app. fullTextSession.index(entity); or session.persist(entity) will index the given entity.

And did you update Hibernate Annotations to 3.3.x in JBoss AS 4.0.5?
If you do so, there is no need to set up the events (it's done automatically). If you don't there might also be some conflits, I have never tested that combo

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 8:05 pm 
Newbie

Joined: Fri May 18, 2007 3:37 am
Posts: 2
Thanks Emmanuel.

This make sense. What would i have to do if i was using the FSDirectoryProvider. I tried the FSDirectoryProvider and it gave me no results too? I'll check for the version as you mentioned.

Regards
yll


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.