Ask Your Question
3

What is the solution to prevent repeated entities when using Criteria API for lazy associations fetch?

asked 2022-10-09 11:00:00 +0000

qstack gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-03-29 12:00:00 +0000

djk gravatar image

One solution to prevent repeated entities when using Criteria API for lazy associations fetch is to use the distinct method of CriteriaQuery. This will eliminate duplicates from the result set. Another solution is to use the fetch method with the JoinType.LEFT parameter, as it will only fetch the associated entities once. Additionally, you can also use the setResultTransformer method to transform the result set into a customized format, which may eliminate duplicates as well.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-10-09 11:00:00 +0000

Seen: 10 times

Last updated: Mar 29 '23