I am implementing hibernate full text search on my jpa entities. In one of the jpa entities I want to specify the document id on a field other than id field, which is unique.
When I index, it indexes. But the document id field value is overwritten by the value of my pk field and hence when I search, it does not fetch the objects from the database as it does not find the matching records in the database.
Here is my sample class.
Code:
@Entity
@Indexed
@Table(name="employee")
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id")
@Field(name="id", index = Index.UN_TOKENIZED, store = Store.YES)
private Integer id;
@Field(name="name", index = Index.TOKENIZED, store = Store.YES)
@Column(name="name")
private String name;
@DocumentId(name="entityid")
@Column(name="entityid")
private Integer entityId;
....
...
For eg:, If my database table has records as follows:
Code:
id name entityid
-------------------------------------
1 empname1 101
2 empname2 102
3 empname3 103
4 empname4 104
Problem 1: Document id is overwritten by the value of id.
After indexing, if I search for name: empname*, it finds 4 matching objects, but then, it does not retrieve the objects from the database because, in the index, entities id values would be 1,2,3,4 and hence it does not find matching records which has entityid 1 or 2 or 3 or 4.
Problem 2: More than one @DocumentId specified on entity
When I move the property document id and related code on to the top before the @id property and code, while indexing it gives an error saying "More than one @DocumentId specified on entity"