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