Bug in NOT MEMBER OF translation? [message #520957] |
Mon, 15 March 2010 18:58  |
Eclipse User |
|
|
|
Coming back to my earlier example :
"SELECT interest, COUNT(contact) AS nbContacts " +
"FROM SocialEntity soc LEFT JOIN FETCH soc.interests, IN(soc.contacts) contact, " +
"IN(contact.interests) interest " +
"WHERE soc = :socialEntity AND interest NOT MEMBER OF soc.interests " +
"GROUP BY interest ORDER BY nbContacts DESC"
The request does not work as expected because it works only when soc.interest is empty.
That JPQL request is translated into the following SQL statement:
SELECT interest.ID, interest.NAME, interest.PARENTINTEREST_ID, COUNT(contact.ID)
FROM SOCIALENTITY_INTEREST t4, SOCIAL_ENTITY__CONTACTS t3, SOCIALENTITY soc, SOCIALENTITY contact, INTEREST interest
WHERE (((? = soc.ID) AND NOT EXISTS
(SELECT DISTINCT t6.ID FROM SOCIALENTITY_INTEREST t5, INTEREST t6
WHERE (((t5.entities_ID = soc.ID) AND (t6.ID = t5.interests_ID))
AND ((t4.entities_ID = contact.ID) AND (interest.ID = t4.interests_ID)))) )
AND (((t3.SocialEntity_ID = soc.ID) AND (contact.ID = t3.contacts_ID))
AND ((t4.entities_ID = contact.ID) AND (interest.ID = t4.interests_ID))))
GROUP BY interest.ID, interest.NAME, interest.PARENTINTEREST_ID ORDER BY COUNT(contact.ID) DESC
One can see that the where clause of the subquery does not seem correct.
One would expect something like
WHERE (((t5.entities_ID = soc.ID) AND (t6.ID = t5.interests_ID))
AND ((t4.entities_ID = contact.ID) AND (interest.ID = t4.interests_ID)
AND (interest.ID = t6.ID)))) )
(the content of tables 5 and 6 should be restricted by the interest object, which is not the case currently)
Am I correct or did I miss something?
[Updated on: Tue, 16 March 2010 01:36] by Moderator
|
|
|
|
|
|
|
|
|
Re: Bug in NOT MEMBER OF translation? [message #523321 is a reply to message #523296] |
Thu, 25 March 2010 17:35   |
Eclipse User |
|
|
|
JPQL QUERY
List<Interest> whole = em.createQuery(
"SELECT interest "
+ "FROM SocialEntity soc, IN(soc.contacts) contact, "
+ "IN(contact.interests) interest "
+ "WHERE soc = :socialEntity AND interest NOT MEMBER OF soc.interests ", Interest.class).setParameter("socialEntity", socialEntity).getResultList();
GENERATED SQL
SELECT t0.ID, t0.NAME, t0.PARENTINTEREST_ID FROM SOCIALENTITY_INTEREST t4, SOCIAL_ENTITY__CONTACTS t3, SOCIALENTITY t2, SOCIALENTITY t1, INTEREST t0
WHERE (((? = t2.ID) AND NOT EXISTS (SELECT DISTINCT t6.ID FROM SOCIALENTITY_INTEREST t5, INTEREST t6 WHERE (((t5.entities_ID = t2.ID) AND (t6.ID = t5.interests_ID)) AND ((t4.entities_ID = t1.ID) AND (t0.ID = t4.interests_ID)))) ) AND (((t3.SocialEntity_ID = t2.ID) AND (t1.ID = t3.contacts_ID)) AND ((t4.entities_ID = t1.ID) AND (t0.ID = t4.interests_ID))))
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05891 seconds