@DocumentId
is required if you are using the old-school style of mapping your entities with .hbm.xml
files. If you are use that mapping approach and neglect to annotate a document id, then at startup you will see an exception like this:
org.hibernate.search.SearchException: No document id in: com.mypackage.MyEntity
However, if you are using annotations and have annotated a primary key with @Id
, then you do not have to use @DocumentId
.
To be more precise, the Hibernate Search documentation says that @DocumentId
is optional when using JPA annotations. So perhaps you would still need to use @DocumentId
if you are using Hibernate 3.x-style annotations... I've never tested this.
Either way, Hibernate 4.x deprecates its own mapping annotations in favor of JPA-style annotations, even if you are using Hibernate's Session
rather than JPA's EntityManager
for your queries. So in a nutshell: you need to use @DocumentId
if you are using XML-style mappings... whereas it's optional if you're using annotations, because at this point you should be using JPA-style annotations anyway.