这是JPQL: SELECT e FROM TestEntity e WHERE e.owner IN:所有者 这是它的SQL和参数绑定:
SELECT TENANT_ID, ID, OWNER_ID FROM TEST.TESTENTITY WHERE (((TEST.TESTENTITY.OWNER_ID, TEST.TESTENTITY.TENANT_ID) IN ((?,?))) AND (TENANT_ID = ?))
bind => [1, 236, 1]
TENANT_ID = 1 OWNER_ID = 236
预期的SQL应该是:
SELECT TESTENTITY.TENANT_ID, TESTENTITY.ID, TESTENTITY.OWNER_ID FROM TEST.TESTENTITY JOIN TEST.USER ON TEST.USER.ID=TEST.TESTENTITY.OWNER_ID AND TEST.USER.TENANT_ID=TEST.TESTENTITY.TENANT_ID WHERE (((TEST.USER.OWNER_ID, TEST.USER.TENANT_ID) IN ((?,?))) AND (TESTENTITY.TENANT_ID = ?)) bind => [236, 1, 1]
生成的sql中有两个错误:
没有加入。如果这是一个优化,那很好。但我认为如果需要优化,可能是:
从TEST.TESTENTITY WHERE((TEST.TESTENTITY.OWNER_ID IN(?))和(TENANT_ID =?)中选择TENANT_ID,ID,OWNER_ID bind => [236,1]
因为TENANT_ID已经在末尾附加了。
我误解了吗?任何建议都受到欢迎。感谢