@Lock(LockModeType.PESSIMISTIC_WRITE)
CustomerReview findByReviewIdentifier(String reviewIdentifier);
What happens when the findByReviewIdentifier returns null? Can hibernate lock the reviewIdentifier for a potential insert even if the method returns null?
Thank you!
–
–
–
From a performance point of view, I will consider evaluating the solution with the following changes.
Changing from bidirectional ManyToMany to bidirectional OneToMany
I had a same question on which one is more efficient from DML statements that gets executed. Quoting from Typical ManyToMany mapping versus two OneToMany.
The option one might be simpler from a configuration perspective, but it yields less efficient DML statements.
Use the second option because whenever the associations are controlled by @ManyToOne associations, the DML statements are always the most efficient ones.
Enabling the batching support would result in less number of round trips to the database to insert/update the same number of records.
Quoting from batch INSERT and UPDATE statements
hibernate.jdbc.batch_size = 50
hibernate.order_inserts = true
hibernate.order_updates = true
hibernate.jdbc.batch_versioned_data = true
The current code gets the ProductPlacement
and for each review
it does a saveAndFlush
, which results in no batching of DML statements.
Instead I would consider loading the ProductPlacement
entity and adding the List<CustomerReview> customerReviews
to the Set<CustomerReview> customerReviews
field of ProductPlacement
entity and finally call the merge
method once at the end, with these two changes:
Making ProductPlacement
entity owner of the association i.e., by moving mappedBy
attribute onto Set<ProductPlacement> productPlacements
field of CustomerReview
entity.
Making CustomerReview
entity implement equals
and hashCode
method by using reviewIdentifier
field in these method. I believe reviewIdentifier
is unique and user assigned.
Finally, as you do performance tuning with these changes, baseline your performance with the current code. Then make the changes and compare if the changes are really resulting in the any significant performance improvement for your solution.
–
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.