避免从Hibernate中选择N + 1(Avoid N+1 selects from Hibernate)
在我的项目中,我们有hbm.xml文件,fetch =“select”表示所有关系表的一对多。
例如:一所学校有很多教室,一间教室有很多孩子
所以在我的hbm文件中
school.hbm.xml
<set name =“classrooms” lazy =“false”fetch =“select” >classroom.hbm.xml
<set name =“children” lazy =“false”fetch =“select” >有一种情况我只想获取基于教室div ='A'的学校列表。 但是由于这种映射,hibernate正在为教室做选择,在这种情况下我不想要。
请帮助我如何避免在课堂上做不必要的选择。 无论如何都要覆盖这种获取模式,只能加入学校和教室,而不是孩子
我试过多种选择,但没有运气。 非常感谢您的投入。
In my project we have hbm.xml file which is fetch="select" for one-to-many for all relation tables.
For ex: One school is having many classrooms and one classroom will have many children
so in my hbm file
school.hbm.xml
<set name="classrooms" lazy="false" fetch="select">classroom.hbm.xml
<set name="children" lazy="false" fetch="select">There is a case where I want to fetch only list of schools which are based on classroom div = 'A'. But because of this mapping hibernate is doing select for classroom as well which I don't want in this case.
Please help me how can I avoid doing unnecessary select with classroom. Is there anyway to override this fetch mode and join only with School and classroom and not with children
I tried with multiple options but no luck. Really appreciate for your inputs.
原文:https://stackoverflow.com/questions/32364321
最满意答案
这是一个可变范围问题。
在第22行添加
filename = None
。您收到此错误的原因是因为在第47行中尚未声明变量
filename
。 你在for
循环中的第43行声明它,当循环退出时它不在那里。更多信息可以在这里找到。
It's a variable scope issue.
In line 22 add
filename = None
.The reason you're getting this error is because in line 47 the variable
filename
has not been declared. You declare it in line 43 inside thefor
loop and when the loop exits it's not there.More info can be found here.
相关问答
更多-
你只需要说EHLO才能直接进入STARTTLS : server = smtplib.SMTP('smtp.gmail.com:587') server.ehlo() server.starttls() 此外,您应该真正创建From: , To:和Subject:消息头,以空行与消息正文分开,并使用CRLF作为EOL标记。 例如 msg = "\r\n".join([ "From: user_me@gmail.com", "To: user_you@gmail.com", "Subject: ...
-
我使用以下内容来获取所有电子邮件。 resp,data = mail.uid('FETCH', '1:*' , '(RFC822)') 并获得我使用的所有id : result, data = mail.uid('search', None, "ALL") print data[0].split() 得到: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', ... etc ] 编辑 在我的情况下,以下返回202个日期,这超过了OP正在寻找的日期,并 ...
-
好吧,既然我无法发表评论,我将不得不尝试答案.. 由此判断: Python SMTP Errno 10060也许超时会有所帮助? Well, since I cant post comments yet I'll have to attempt an answer.. Judging by this: Python SMTP Errno 10060 Perhaps a timeout would help?
-
从Gmail API中批量发送超过10k封电子邮件的电子邮件发件人(Get email senders in batch from Gmail API for over 10k emails)[2022-07-31]
根据文档 ,提高性能的一种方法是批量请求。 目前它每个批次有100个请求的限制,但它仍然是100个请求的次数。 编辑:您也可以使用查询中的fields参数来请求消息中的字段,因为messages.list和messages.get都可以返回整个users.messages资源 。 例如: var xhr = new XMLHttpRequest; xhr.onload = () => { var resp = JSON.parse(xhr.response); var wholeFirstM ... -
您已使用从用户输入的字符串覆盖“email”模块。 import email ... email = raw_input("Email address: ") ... mail = email.message_from_string(data[0][1]) 将行email = raw_input("Email address: ")更改为其他名称,例如address = raw_input("Email address: ")并根据需要调整代码。 You've overwritten the "email ...
-
去年我遇到了同样的问题:代码(VB.Net)没问题,所以凭证在哪里。 问题是,gmail不喜欢远程(我的托管)网络服务器中的某些应用程序,尝试使用相同的用户名。 我通过以下方式修复了它(在两个不同的场合): 从该服务器登录一次gmail(使用远程桌面)。 从我的电脑上登录https://accounts.google.com/DisplayUnlockCaptcha以“解锁”远程连接。 之后再次测试您的代码。 I had the same issue last year: the code (VB.Net) ...
-
您可能会发现使用IMAPClient更容易,因为它会为您处理更多低级协议方面。 使用IMAPClient,您的代码将类似于: from imapclient import IMAPClient import email obj = IMAPClient('imap.gmail.com', ssl=True) obj.login('user','pass') obj.select('inbox') delete = [] msg_ids = obj.search(('NOT', 'DELETED')) f ...
-
这是一个可变范围问题。 在第22行添加filename = None 。 您收到此错误的原因是因为在第47行中尚未声明变量filename 。 你在for循环中的第43行声明它,当循环退出时它不在那里。 更多信息可以在这里找到。 It's a variable scope issue. In line 22 add filename = None. The reason you're getting this error is because in line 47 the variable filename ...
-
谷歌最近加强了他们的安全性。 直接使用用户名/密码的应用程序已停用。 所有用户仍然可以在您的安全设置中重新激活这些安全性较低的应用程序,因为您已经阅读了问题中提供的链接。 这是目前唯一的解决方案。 另一种方法是使用其他SMTP服务器进行发送。 Google has recently tightened their security. Application that use username/password directly have been deactivated. All users are sti ...
-
这是行不通的,因为我在imap_search中使用了ALL,因此获得了大量邮件并且无法传递大量邮件。 我根据搜索条件更改了代码以获得限制,并且工作正常 ALL - return all messages matching the rest of the criteria ANSWERED - match messages with the \\ANSWERED flag set BCC "string" - match messages with "string" in the Bc ...