hibernate-search for one-directional associations


According to the <a href="https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#search-mapping-associated" rel="nofollow">spec</a>, when <em>@IndexedEmbedded points to an entity, the association has to be directional and the other side has to be annotated with @ContainedIn. If not, Hibernate Search has no way to update the root index when the associated entity is updated</em>.

Am I right to assume the word <em>directional</em> should be <em>bi-directional</em>? I have exactly the problem that my index is not updated. I have one-directional relationships, e.g. person to order but the order does not know the person. Now when I change the order the index is not updated.

If changing the associations to become bi-directional is no option which possibilities would I have to still use hibernate-search? Would it be possible to create two separate indices and to combine queries?



Am I right to assume the word directional should be bi-directional?


Yes. I will fix this typo.


If changing the associations to become bi-directional is no option which possibilities would I have to still use hibernate-search?


If Person is indexed and embeds Order, but Order doesn't have an inverse association to Person, then Hibernate Search cannot retrieve the Persons that have to be reindexed when an Order changes.

Thus you will have to reindex manually: <a href="https://docs.jboss.org/hibernate/search/5.11/reference/en-US/html_single/#manual-index-changes" rel="nofollow">https://docs.jboss.org/hibernate/search/5.11/reference/en-US/html_single/#manual-index-changes</a> .

You can adopt one of two strategies:

<ol><li>The easy path: reindex all the Person entities periodically, e.g. every night.</li> <li>The hard path: reindex the affected Person entities whenever an Order changes. This basically means adding code to your services so that whenever an order is created/updated/deleted, you run a query to retrieve all the corresponding persons, and reindex them manually. </li> </ol>

The first solution is fairly simple, but has the big disadvantage that the Person index will be up to 24 hours out of date. Depending on your use case, that may be ok or that may not.

The second solution is prone to errors and you would basically be doing Hibernate Search's work.

All in all, you really have to ask yourself if adding the inverse side of the association to your model wouldn't be better.


Would it be possible to create two separate indices and to combine queries?


Technically, if you are using the Lucene integration (not the Elasticsearch one), then yes, it would be possible.


<ul><li>you would need above-average knowledge of Lucene.</li> <li>you would have to bypass Hibernate Search APIs, and would need to write code to do what Hibernate Search usually does.</li> <li>you would have to use experimental (read: unstable) Lucene APIs.</li> <li>I am unsure as to how well that would perform, as I never tried it.</li> </ul>

So I wouldn't recommend it if you're not familiar with Lucene's APIs. If you really want to take that path, here are a few pointers:

<ul><li>How to use the index readers directly: <a href="https://docs.jboss.org/hibernate/search/5.11/reference/en-US/html_single/#IndexReaders" rel="nofollow">https://docs.jboss.org/hibernate/search/5.11/reference/en-US/html_single/#IndexReaders</a></li> <li>Lucene's documentation for joins (what you're looking for is query-time joins): <a href="https://lucene.apache.org/core/5_5_5/join/org/apache/lucene/search/join/package-summary.html" rel="nofollow">https://lucene.apache.org/core/5_5_5/join/org/apache/lucene/search/join/package-summary.html</a></li> </ul>


  • Air sub applications
  • How to invoke the buffer list in Emacs
  • Why does AWK not treat this array index as a number unless I use int()?
  • FindNextFile fails on 64-bit Windows?
  • CSS - select element without text inside
  • Calling functions from a Tkinter Frame to an other
  • CSS style are not applying when I import them from an external file
  • Issue in open my application from browser url in android
  • Is there a way to continuously pipe data from Azure Blob into BigQuery?
  • Adding batch script to Windows 8 context menu
  • Metro Flyouts with MVVM
  • how do I cluster a list of geographic points by distance?
  • How can I make an image interactive? [closed]
  • Passing a list of parameters into a Python function [duplicate]
  • WCF Services with JSON, JSONP and SOAP End Points
  • Replacing call to setImageResource() with setImageBitmap to reduce hiccup?
  • .Net how to set IsReadOnly for a property for a usercontrol
  • java.lang.NumberFormatException: unable to parse '' as integer one more time
  • How to HTTP POST a Blob to a different domain? [duplicate]
  • Create One-To-One relationship between table and view in EF4?
  • .htaccess redirect domain.com to www.domain.com
  • MFMailComposer send email without presenting view
  • Scheme procedure to compute the nth repeated application of a function?
  • Unable to run testNG tests from maven
  • Synchronous Calls with jqGrid?
  • playing mp3 from nsbundle
  • How to use Typescript with libraries like Ampersand.js that parse configs to build prototypes
  • Wireshark Display Filter for Unique Source/Destination IP and Protocol
  • Django, uWSGI & nginx: Process dies for “no reason”
  • Is there a better way for handling SpatialPolygons that cross the antimeridian (date line)?
  • Python 3x- Compression Makes File Bigger :(
  • Amazon Elastick BeanStalk error: Failed to create the AWS Elastic Beanstalk application version
  • How to call jQuery function in HTML returned by AJAX
  • How do I add a mouse over tooltip to an Image using .DrawImage()
  • How to warp text around image in iOS?
  • Did not understand process of initialize in swift programming
  • What is the best way to cache and reuse immutable singleton objects in Java?