Is @DocumentId required to search in sleep mode?

I use Hibernate Search, and the documentation and books say I need @DocumentId in the id field so that Hibernate Search can know how to map the index to objects.

My code works fine without @DocumentId anywhere in my code. Has Hibernate Search become smart enough to realize that the @Id field is a great default? Are there any problems that make this not obvious?

Thank you for your time!

+5
source share
1 answer

@DocumentIdrequired if you are using an old school style to map objects to .hbm.xmlfiles. If you use this approach for matching and ignore the annotation of the document identifier, then at startup you will see the following exception:

org.hibernate.search.SearchException: No document id in: com.mypackage.MyEntity

However, if you use annotations and annotate the primary key with @Id, you do not need to use @DocumentId.

To be more precise, the Hibernate Search documentation indicates what @DocumentIdis optional when using JPA annotations . Therefore, you may need to use @DocumentIdit if you use Hibernate 3.x annotations. I have never tested this.

, Hibernate 4.x JPA-, , Hibernate Session, JPA EntityManager . , : @DocumentId, XML... , , JPA- .

+4

All Articles