3 Replies Latest reply on Oct 28, 2007 10:01 AM by slavosk

    Seam 2.0.0 and hibernate search

    slavosk

      Hello,

      Did someone tried succesfully to configure hibernate search with seam2 ?

      I'm evaluating the seam & hsearch solution and need a little help.

      I have a problem to create an index. I have a seam-gen generated project and configured hibernate search following way:

      persistence.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <!-- Persistence deployment descriptor for prod profile -->
      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
       version="1.0">
      
       <persistence-unit name="crud9">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/crud9Datasource</jta-data-source>
       <properties>
      <!-- <property name="hibernate.hbm2ddl.auto" value="validate"/> -->
       <property name="hibernate.cache.use_query_cache" value="true"/>
       <property name="hibernate.jdbc.batch_size" value="20"/>
       <property name="jboss.entity.manager.factory.jndi.name" value="java:/crud9EntityManagerFactory"/>
       <property name="hibernate.default_schema" value="core"/>
      
       <!-- use a file system based index -->
       <property name="hibernate.search.default.directory_provider"
       value="org.hibernate.search.store.FSDirectoryProvider"/>
       <!-- directory where the indexes will be stored -->
       <property name="hibernate.search.default.indexBase"
       value="/data/hs_index"/>
      
       </properties>
       </persistence-unit>
      
      </persistence>
      
      



      application.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <application xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd"
       version="5">
      
       <display-name>crud9</display-name>
      
       <module>
       <web>
       <web-uri>crud9.war</web-uri>
       <context-root>/crud9</context-root>
       </web>
       </module>
      
       <module>
       <ejb>crud9.jar</ejb>
       </module>
      
       <!-- Seam and EL -->
       <module>
       <ejb>jboss-seam.jar</ejb>
       </module>
       <module>
       <ejb>hibernate-search.jar</ejb>
       </module>
       <module>
       <ejb>hibernate-commons-annotations.jar</ejb>
       </module>
       <module>
       <ejb>lucene-core-2.2.0.jar</ejb>
       </module>
      
      </application>
      


      Entity annotations:

      
      @Entity
      @Table(name = "products")
      
      @Indexed(index="products")
      public class PrProduct implements java.io.Serializable {
      ....
       @Id
       @DocumentId
       @Column(name = "product_id", unique = true, nullable = false, length = 20)
       @NotNull
       @Length(max = 20)
       public String getProductId() {
       return this.productId;
       }
      
      ....
       @Column(name = "name", length = 128)
       @Field(index=Index.TOKENIZED,store=Store.YES)
       @Length(max = 128)
      
       public String getName() {
       return this.name;
       }
      
       public void setName(String name) {
       this.name = name;
       }
      ...
       @Column(name = "desc", length = 4000)
       @Field(index=Index.TOKENIZED,store=Store.YES)
       @Length(max = 4000)
       public String geDesc() {
       return this.desc;
       }
      ....
      


      More fields (ca 10), but I tried to index theese...

      I don't become any error, but I don't see anything under /data/hs_index after I run following indexing code:

      
      @Name("prProductHome")
      
      public class PrProductHome extends EntityHome<PrProduct> {
       @In
       EntityManager entityManager;
      
      ....
       public String createHsIndex(){
       try {
       FullTextEntityManager ftEm = (FullTextEntityManager) entityManager;
       Query q = entityManager.createQuery("select prProduct from PrProduct prProduct");
      
       List<PrProduct> products = q.setMaxResults(200).getResultList();
      
       for (PrProduct prProduct : products) {
       ftEm.index(prProduct);
       }
      
       } catch (Exception e) {
       log.error("Probleeeem: #0", e.getMessage());
       }
       return "OK";
       }
      
      ....
      



      Can you give me a hint what's wrong or where to search ???


      Versions: (From JBoss Log)
      Hibernate EntityManager 3.2.1.GA
      Hibernate Annotations 3.2.1.GA
      Hibernate 3.2.4.sp1
      Hibernate Search 3.0.0.CR1.HSEARCH-116


      Thank you,
      SlavoSk


        • 1. Re: Seam 2.0.0 and hibernate search
          pmuir

          Both the wiki and dvdstore use hibernate search - take a look at those examples.

          • 2. Re: Seam 2.0.0 and hibernate search
            slavosk

            Hello Pete,
            Thank you for answer.

            I looked at the example. The only think I found was I don't call getDelegate().

            FullTextEntityManager ftEm = (FullTextEntityManager) em.getDelegate();
            


            But when I do this I become an error:
            java.lang.ClassCastException: org.jboss.seam.persistence.FullTextHibernateSessionP
            roxy
            


            Where could be the problem ? Versions of hibernate-search, hibernate annotation, hibernate entityManager ?

            Slavo



            • 3. Re: Seam 2.0.0 and hibernate search
              slavosk

              Now it works.
              The problem was I used bad @Indexed annotation (from lucene, not from hibernate)