-->
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.  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Indexing Hibernate Search Problem
PostPosted: Wed Feb 27, 2008 12:54 pm 
Beginner
Beginner

Joined: Wed Feb 27, 2008 12:34 pm
Posts: 21
Hi,

I am trying to index the persisted entities with the code:

EntityManager em = JpaUtil.getEntityManager(this.getJpaTemplate().getEntityManagerFactory());
FullTextEntityManager fullTextEntityManager = Search.createFullTextEntityManager(em);
List<Book> books = em.createQuery("select book from Book as book").getResultList();

for (Book book : books) {
fullTextEntityManager.index(book);

}


Everything seems ok but the sentence fullTextEntityManager.index(book) doesn't work. There is no error but it doesn't do anything.

In the persistence.xml file I've got:


<properties>
<!-- 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="c:/lucene"/>

</properties>


Any idea?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 27, 2008 4:45 pm 
Newbie

Joined: Wed Feb 20, 2008 6:42 pm
Posts: 14
Just a naive answer - are you sure you marked the Book entity as indexable ?

thanks
Anil.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 27, 2008 4:58 pm 
Beginner
Beginner

Joined: Wed Feb 27, 2008 12:34 pm
Posts: 21
Yes, I am.

Thanks a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 27, 2008 5:02 pm 
Newbie

Joined: Wed Feb 20, 2008 6:42 pm
Posts: 14
It still doesn't work ? And I also believe you are using the right version of every thing.

thanks
Anil.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 27, 2008 5:59 pm 
Beginner
Beginner

Joined: Wed Feb 27, 2008 12:34 pm
Posts: 21
I think so but it still doesn't work.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 27, 2008 11:16 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
A couple of things to check:
- how do you know he does not do anything? Did you try opening the index with Luke?
- did you use transactions? commit?
- did you mark your entity as @Indexed (AFAIR non @Indexed entities will simply be silently ignored)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 4:40 am 
Beginner
Beginner

Joined: Wed Feb 27, 2008 12:34 pm
Posts: 21
1-Yes, I did. There is no index.
2-No.
3-Yes

Could be a version problem? I'm using hibernate-annotations-3.2.1.ga

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 4:56 am 
Beginner
Beginner

Joined: Wed Feb 27, 2008 12:34 pm
Posts: 21
More details:

If I do:

fullTextEntityManager.flush(); or

fullTextEntityManager.getTransaction().commit();

it doesn't do anything. However, if I do fullTextEntityManager.isOpen(), it returns true.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 5:10 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
maybe you declared the index with the wrong path separator char:

Code:
<property name="hibernate.search.default.indexBase"
value="c:/lucene"/>

should be
Code:
<property name="hibernate.search.default.indexBase"
value="c:\lucene" />
or (not sure)
Code:
<property name="hibernate.search.default.indexBase"
value="c:\\lucene" />

(not having windows, so I don't know exactly)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 5:29 am 
Beginner
Beginner

Joined: Wed Feb 27, 2008 12:34 pm
Posts: 21
The path separator char is correct.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 6:33 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
What do you mean?
Did you solve it or still needing help?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 7:15 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Carpenter, providing informations about your environment in a laconic way is not going to help resolve your problem, it wastes everybody's time including yours and will most likely annoy everybody around.

People need:
- your config file (all of it), we can't see if you've configured the event properly
- the logs, especially the version numbers showing in it
- the code that shows that nothing happened (did you try and run a query?)

There was a template in your initial post that you decided to not follow. Follow it

Quote:
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


_________________
Emmanuel


Top
 Profile  
 
 Post subject: Similar problem
PostPosted: Tue Apr 08, 2008 6:30 am 
Newbie

Joined: Tue Apr 08, 2008 6:21 am
Posts: 3
Hello,

I have a similar problem. Here is my persistence.xml:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Persistence deployment descriptor for dev profile -->
<persistence version="1.0" 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">
  <persistence-unit name="ulbapps">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:/ULBAppsDS</jta-data-source>
    <!--class>de.wwu.ulb.ulbapps.subjects.model.Subject</class>
    <class>de.wwu.ulb.ulbapps.subjects.model.SubjectUser</class-->
    <properties>
      <property name="hibernate.hbm2ddl.auto" value="update"/>
      <property name="hibernate.cache.use_query_cache" value="true"/>
      <property name="hibernate.show_sql" value="false"/>
      <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
      <property name="jboss.entity.manager.factory.jndi.name" value="java:/ULBAppsEntityManagerFactory"/>
      <property name="hibernate.ejb.event.post-update" value="org.hibernate.search.event.FullTextIndexEventListener"/>
      <property name="hibernate.ejb.event.post-insert" value="org.hibernate.search.event.FullTextIndexEventListener"/>
      <property name="hibernate.ejb.event.post-delete" value="org.hibernate.search.event.FullTextIndexEventListener"/>
      <property name="hibernate.search.autoregister_listeners" value="true"/>
      <property name="hibernate.search.default.directory_provider" value="org.hibernate.search.store.FSDirectoryProvider"/>
      <property name="hibernate.search.default.indexBase" value="/home/gressho/lucene"/>
    </properties>
  </persistence-unit>
</persistence>


The indexBase is in my home dir and JBoss runs with my user id, so it
should be writable. My environment is a JBoss AS 4.2.2 (with original
hibernate and hibernate annotations in server/default/lib) which
runs on JDK 1.5 update 15 on a linux machine. My application is an
EJB3 application, so the transactions start in a stateless session bean:

Code:
    public void save(ItemVO itemVO) {
        if (itemVO.getId() == 0) {
            Item item = new Item();
            item.setContent(itemVO.getContent());
            Context context = em.find(
                    Context.class, itemVO.getContext().getId());
            context.getItems().add(item);
            item.setContext(context);
            for (DescriptionVO descriptionVO : itemVO.getDescriptions()) {
                if (descriptionVO.getDescription().length() > 0) {
                    Description description = new Description();
                    description.setDescription(descriptionVO.getDescription());
                    description.setItem(item);
                    item.getDescriptions().add(description);
                }
            }
            for (UrlVO urlVO : itemVO.getUrls()) {
                if (urlVO.getUrl().length() > 0) {
                    Url url = new Url();
                    url.setUrl(urlVO.getUrl());
                    url.setDescription(urlVO.getDescription());
                    url.setItem(item);
                    item.getUrls().add(url);
                }
            }
            item.setTimeChanged(itemVO.getTimeChanged());
            item.setTimeCreated(new Date());
            item.setTimeExpired(itemVO.getTimeExpired());
            em.persist(item);
        } else {
            Item item = em.find(Item.class, itemVO.getId());
            for (Iterator<Description> iterator =
                    item.getDescriptions().iterator();
                    iterator.hasNext(); ) {
                Description description = iterator.next();
                iterator.remove();
                em.remove(description);
            }
            for (DescriptionVO descriptionVO : itemVO.getDescriptions()) {
                if (descriptionVO.getDescription().length() > 0) {
                    Description description = new Description();
                    description.setDescription(descriptionVO.getDescription());
                    description.setItem(item);
                    item.getDescriptions().add(description);
                }
            }
            for (Iterator<Url> iterator =
                    item.getUrls().iterator();
                    iterator.hasNext(); ) {
                Url url = iterator.next();
                iterator.remove();
                em.remove(url);
            }
            for (UrlVO urlVO : itemVO.getUrls()) {
                if (urlVO.getUrl().length() > 0) {
                    Url url = new Url();
                    url.setUrl(urlVO.getUrl());
                    url.setDescription(urlVO.getDescription());
                    url.setItem(item);
                    item.getUrls().add(url);
                }
            }
            item.setContent(itemVO.getContent());
            item.setTimeChanged(new Date());
            item.setTimeExpired(itemVO.getTimeExpired());
            em.merge(item);
        }
    }


which uses the entity bean

Code:
/*
*  Copyright 2008 gressho.
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*       http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*  under the License.
*/

package de.wwu.ulb.ulbapps.si.model;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;

/**
*
* @author gressho
*/
@Entity
@Table(name = "SI_ITEM_T")
@Indexed(index = "indexes/si")
public class Item implements Serializable {
    private static final long serialVersionUID = 1L;
    private Integer id;
    private String content;
    private Set<Description> descriptions = new HashSet<Description>();
    private Set<Url> urls = new HashSet<Url>();
    private Context context;
    private Date timeCreated;
    private Date timeChanged;
    private Date timeExpired;
   
    public void setId(Integer id) {
        this.id = id;
    }

    @Id
    @Column(name = "ID", nullable = false)
    @GeneratedValue(strategy = GenerationType.AUTO)
    @DocumentId
    public Integer getId() {
        return id;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Lob
    @Basic(fetch = FetchType.LAZY, optional = true)
    @Field(index = Index.TOKENIZED)
    public String getContent() {
        return content;
    }

    public void setContext(Context context) {
        this.context = context;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CONTEXT_ID")
    public Context getContext() {
        return context;
    }

    public void setDescriptions(Set<Description> descriptions) {
        this.descriptions = descriptions;
    }

    @OneToMany(mappedBy = "item",
            fetch = FetchType.LAZY,
            cascade = CascadeType.ALL)
    public Set<Description> getDescriptions() {
        return descriptions;
    }

    public void setUrls(Set<Url> urls) {
        this.urls = urls;
    }

    @OneToMany(mappedBy = "item",
            fetch = FetchType.LAZY,
            cascade = CascadeType.ALL)
    public Set<Url> getUrls() {
        return urls;
    }

    public void setTimeChanged(Date timeChanged) {
        this.timeChanged = timeChanged;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "CHANGEDATE")
    public Date getTimeChanged() {
        return timeChanged;
    }

    public void setTimeCreated(Date timeCreated) {
        this.timeCreated = timeCreated;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "CREATEDATE")
    public Date getTimeCreated() {
        return timeCreated;
    }

    public void setTimeExpired(Date timeExpired) {
        this.timeExpired = timeExpired;
    }
   
    @Temporal(TemporalType.DATE)
    @Column(name = "EXPIRATIONDATE")
    public Date getTimeExpired() {
        return timeExpired;
    }

}


The result is: the directory /home/gressho/lucene/indexes/si stays
empty either after an persist or a merge.
I'm using hibernate-search 3.0.1.GA and hibernate-commons-annotations-3.0.0.ga and lucene 2.3.0
(additionaly to the provided hibernate 3.2.4.SP1 from JBoss)

Best wishes

Werner


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 6:42 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
Quote:
the directory /home/gressho/lucene/indexes/si stays
empty either after an


The last subdirectory must not exist, you should delete the "si" dir.
All paths up to the last are automatically created, but if the last one exists lucene will think the index already exists.
I will see if it is possible to print some sort of warning automatically, as this is happening to more people.

regards,
Sanne


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Wed Apr 09, 2008 1:40 am 
Newbie

Joined: Tue Apr 08, 2008 6:21 am
Posts: 3
Thanks Sanno,

you were perfectly right! It works now!!!

Werner


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 17 posts ]  Go to page 1, 2  Next

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.