-
Yes, I am using a framework that takes care of that.
-
Isn’t the
@Id
+@Embeddable
approach to composite keys valid anymore? It’s been working ok so far.
http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html/entity.html#d0e2177 -
Yes, it’s possible and it works. You may want to take a look at Example 149 of the Hibernate ORM user guide under section 2.6.3. Composite identifiers with @EmbeddedId (*).
-
Yes, I can change the schema. There seems to have been some debate between using a technical ID as you mention and a natural composite ID (for example, “Why are composite keys discouraged in hibernate?” in Stack Overflow (*)). Is the Hibernate recommendation to always use the former? Unicity at the DB level must be guaranteed so I will keep your unique index suggestion in mind.
-
Each SomeEntity returned in the (paginated) search results points to a single SomeOtherEntity. However, because different SomeEntities may refer to the same SomeOtherEntity, some (post-search) filtering is required:
Query fullTextQuery = fullTextEntityManager.createFullTextQuery(searchQuery, SomeEntity.class);
List<SomeEntity> someEntities = fullTextQuery.setFirstResult(...).setMaxResults(...).getResultList();
List<SomeOtherEntity> someOtherEntities = someEntities.stream().map(s -> s.getId().getIdPart1()).distinct().collect(Collectors.toList());
(wondering if this distinct-like filtering could be achieved at the Hibernate Search level)
As you wrote, SomeOtherEntity instances are not included in the results and that would be the ideal case. Because the relationship between SomeOtherEntity and SomeEntity is actually “one-to-few”, I started with @OneToMany between them. The SomeOtherEntity index included several SomeOtherEntities and I could search
“SomeOtherEntities having SomeEntities with property1 matching X OR property2 matching Y”
but not
“SomeOtherEntities having SomeEntities with property1 matching X AND property2 matching Y”
which is a problem that nested objects solve (www.elastic.co/guide/en/elasticsearch/guide/current/nested-objects.html). Because Hibernate Search does not yet support nested objects, I ended up turning to the “other side” of the relationship in order to be able to 1) perform AND-like queries on separate SomeEntity documents and 2) retrieve the corresponding SomeOtherEntity ones.
(*) There’s a limit of 2 links per post, so I had to replace some URLs.