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