Hi,
I'm using Hibernate annotations with lucene in my application.
This simple program persists an entity then delete it just after.
The entity which is persisted is also indexed in a file using lucene.
Here is the code :
Code:
public void run() {
// create alarm
Alarm alarm = new Alarm();
alarm.setName("new");
Alarm created = service.create(alarm);
// get primary key of created alarm
Long pk = created.getOid();
// delete alarm
service.delete(pk);
}
Code:
@Entity
@Indexed(index="searchindexes")
public class Alarm {
private String name;
private Long oid;
private Integer version;
@Field(index=Index.TOKENIZED,store=Store.YES)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_STORE")
@DocumentId
public Long getOid() {
return this.oid;
}
public void setOid(Long oid) {
this.oid = oid;
}
@Version
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
}
I would like to simulate several clients in my application, so I put this code in a Thread. Thus, all clients are executing their requests at the same time.
The problem is that if I execute my application with more than 3 threads, then I get the following exception :
Code:
java.io.IOException: IndexReader out of date and no longer valid for delete, undelete, or setNorm operations
at org.apache.lucene.index.IndexReader.aquireWriteLock(IndexReader.java:499)
at org.apache.lucene.index.IndexReader.deleteDocument(IndexReader.java:514)
at org.hibernate.search.backend.impl.LuceneWorker.remove(LuceneWorker.java:100)
If I increase the number of threads to 15, I've also the following exception :
Code:
java.io.IOException: Lock obtain timed out: Lock@C:\DOCUME~1\user\LOCALS~1\Temp\lucene-1892baef65d90cfb4f1135a0920fae48-write.lock
at org.apache.lucene.store.Lock.obtain(Lock.java:56)
at org.apache.lucene.index.IndexReader.aquireWriteLock(IndexReader.java:489)
at org.apache.lucene.index.IndexReader.deleteDocument(IndexReader.java:514)
at org.hibernate.search.backend.impl.LuceneWorker.remove(LuceneWorker.java:100)
Bellow three simulated users, it works, but with four users or more, It fails!
So my question is : Is Hibernate Search thread safe?
Hibernate version: 3.2.2 GA
Hibernate Annotations: 3.2.1 GA
Name and version of the database you are using: Oracle 10