Could this be the n + 1 problem?
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 PolicySetType
s 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/.
精彩评论