ColdFusion 9 ORM/Hibernate 和远程处理
为什么我的 cfc 方法(返回 JSON 格式或通过远程处理调用时)会返回所有相关对象,而不管属性上的惰性设置如何?
Why does my cfc method (when returning JSON format or called via remoting) return all related objects regardless of the lazy setting on the property?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是,当 CF 将这些对象序列化为 JSON 时,它被迫调用相关对象的 getter,这反过来又导致它们在数据库中查找。 “lazy”属性控制是否在检索主对象期间检索相关对象,或者延迟到您实际请求它们为止。在这种情况下,当序列化对象时,相关对象要么根据返回的 JSON 进行查找,要么不根据返回的 JSON 进行查找,因此无论惰性设置如何,它们都会返回。
基本上,如果您有棒球运动员和球队的数据结构,如果为选定球员(即乔什·贝克特)返回的 JSON 调用有关球队(即红袜队)的信息,则无论惰性属性设置如何,该球队对象都会当您获取玩家对象或请求与玩家相关的团队对象时检索。
有道理吗?
My guess is that when CF serializes those objects into JSON, it is forced to call the getters for the related objects, which in turn causes them to looked up in the database. The "lazy" property controls whether or not related objects are retrieved during the retrieval of the main objects or delayed until you actually request them. In this case, when serializing the object, the related objects are either looked up or not based on the JSON returned, so regardless of the lazy setting, they'll come back.
Basically, if you have a data structure of baseball players and teams, if the JSON returned for a selected player (i.e. Josh Beckett) calls for info about the team (i.e. Red Sox), regardless of the lazy property setting, that team object will either be retrieved when you get the player object or when you ask for the team object that relates to the player.
Make sense?