开发者

Could this be the n + 1 problem?

开发者 https://www.devze.com 2023-03-24 00:56 出处:网络
In a program I have to maintain, there is one point where a single, simple query is executed. The query looks like this:

In a program I have to maintain, there is one point where a single, simple query is executed.

The query looks like this:

<named-query name="retrievePolicySet">
    <query>from PSTRepresentationType p where p.realm=? AND p.policySetType.policySetId=?</query>
</named-query>

The type PSTRepresentationType has a many-to-one association, mapping many PolicySetTypes to one PSTRepresentationType.

When the query gets exe开发者_开发知识库cuted, it not only creates one but 45 additional select statements! Could this be a n + 1 problem?


Yes it is. I believe for your case the left join fetch solution should work: http://www.javalobby.org/articles/hibernate-query-101/.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号