-
I'm creating an entity view for a class BookHolder which has a basic id field, plus three lists of sub entities (each using a respective view) - rules, captures and books. The database for BookHolder with id 1 has:
The BookHolderView comes back with the id, 1 rule (id 3), 2 books (id 4 and 5) but 2 captures (both id 2 - so clearly duplicates). When i remove the books from the view, only 1 capture comes back. So my understanding is that the join in the query is causing duplicate rows. However Blaze must be attempting to de-duplicate here, as only 1 rule comes back in the final view - which is correct. I'm guessing that the configuation of the Capture entity is causing an issue with the de-duplication. Unfortunately i'm not able to share code at this point, but we have checked the entity and there is nothing obvious that stands out (e.g. a json converter) that are being used compared to the Rule entity. I've tried generating a proper equals and hashcode generated by JPA buddy, but this had no effect. I'm just curious to how Blaze de-duplicates Sub Entity Views when using a join fetched strategy, as this might shed some light on why the Capture is duplicated. I'm aware of using a sub select strategy and this does work, however it is concerning we have a bug somewhere in our code for Rules to not being duplicated but Captures are when using a join fetch strategy. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi, Maybe one of your lists has an index column in the entity model i.e. I would recommend you to mostly use a |
Beta Was this translation helpful? Give feedback.
Hi,
AFAIR, Blaze-Persistence does not attempt to de-duplicate elements of non-indexed collections. You can debug the implementation
com.blazebit.persistence.view.impl.objectbuilder.transformer.NonIndexedTupleListTransformer
.Maybe one of your lists has an index column in the entity model i.e.
@OrderColumn
? The presence of that makes it an indexed list which is de-duplicated since the index provides row identity.I would recommend you to mostly use a
Set
instead orSortedSet
if you want a particular ordering. If the order of the elements matters to you, you should always use an@OrderColumn
in your entity mapping.