我遇到了jpa查询的问题:
SELECT DISTINCT p FROM Product p INNER JOIN p.shopCategories sc WHERE EXISTS (SELECT DISTINCT sc2 FROM Customer c INNER JOIN c.shopCategories as sc2 WHERE c.customerId=7)
结果应该只是具有商店类别的页面,其中客户已经预订了该商店类别。
产品< - > ShopCategory< - >客户
但结果是包含任何ShopCategory存在的所有产品的列表。
如何改进查询?
答案 0 :(得分:0)
我会一直加入客户
[DataContract]
public class Request
{
[DataMember]
public Child Child { get; set; }
}
[DataContract]
public class Child
{
[DataMember]
public CountryISO CountryISO { get; set; }
}
[DataContract]
public class CountryISO
{
[DataMember]
[XmlElement("country")]
public List<string> country { get; set; }
}
如果您的ShopCategories实体当然有双向映射。
<强>更新强>
使用EXISTS,我认为你需要将内部查询与父查询相关联:
from circuits.web.client import Client, request as request_event
from circuits.web import Server, Controller
from circuits import handler
class Root(Controller):
@handler('request')
def _on_request(self):
a = yield self.wait(request_event('GET', 'https://www.w3.org/services/html2txt?url=http%3A%2F%2Fwww.example.com%2F'), channel='url-fetching')
b = yield self.wait((request_event('GET', 'http://home.hiwaay.net/~jimes/checklist.txt'), channel='url-fetching')
self.response.headers["Content-Type"] = "text/plain"
self.response.body = "%s %s" % (a.value.read(), b.value.read())
(Server(('0.0.0.0', 8011)) + Root() + Client(channel='url-fetching').run()