An entity whose embedded ID includes a transient field set on a non-transient field setter of the same class
A FullTextQuery (Hibernate Search) that returns projected FullTextQuery.THIS entities
If a single entity is returned, its ID transient field is correctly set to a non-null value. However, for two or more entities being returned, their ID transient fields are set to null.
Changing the database retrieval method from
makes it work i.e. the ID transient field of each returned entity is correctly set to a non-null value, although at the cost of performance, as DatabaseRetrievalMethod.QUERY uses criteria query.
Regardless of the DB retrieval method being used, the results should be the same
The @PostLoad annotation could work for embedded IDs in order to avoid having transient fields set somewhere else (constructor or another field's setter method)
The call trace to FullTextQuery.getResultList goes more or less like this:
At this point, the flow diverges for the different database retrieval methods:
(1) returns non-transient fields only i.e. the transient field is lost
(2) based on (1), returns entities with non-transient fields only i.e. without the transient one
(4) returns the entity with all fields (non-transient and transient) set.
Furthermore, before the part where the flow diverges, in the AbstractLoader class, there’s the following logic:
According to this logic, if a single entity is being loaded (else if block) then the flow goes to (3) i.e. the entity is returned with all fields (non-transient and transient) set. This seems to explain why, although not working for multiple entities, DatabaseRetrievalMethod.QUERY works when a single entity is being returned.
DB: MySQL 5.7.22
JVM: Oracle 1.8.0_171-b11
OS: Ubuntu 16.04.4 LTS