Hi,
I'm using Hibernate annotations with lucene in my program.
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)
Bellow three simulated users, it works, but with four users or more, It fails!
Hibernate version: 3.2.0
Lucene version: 2.0.0
Name and version of the database you are using: Oracle 10