测试 grails 属性是否是惰性的/未初始化的?
我似乎无法测试对象是否延迟初始化。我在这里做错了什么?
public void testLazy(){
User lazyUser = User.withCriteria {
like("userId", 'test')
fetchMode("preferences", FetchMode.LAZY )
}.get(0)
assertFalse( "DOM objects of user were not lazy initialized",
GrailsHibernateUtil.isInitialized(lazyUser, "preferences") )
}
I can't seem to test if an object is lazy initialized. What am I doing wrong here?
public void testLazy(){
User lazyUser = User.withCriteria {
like("userId", 'test')
fetchMode("preferences", FetchMode.LAZY )
}.get(0)
assertFalse( "DOM objects of user were not lazy initialized",
GrailsHibernateUtil.isInitialized(lazyUser, "preferences") )
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你做得很好。
完全相同的代码片段对我有用 - 对于(子域对象)属性的集合,
isInitialized()
返回false
,对于字符串属性 -true.也许 FetchMode.LAZY 并不能保证 - 如果您请求一个简单类型,它无论如何都会被获取。
首选项
的类型是什么?You're doing all right.
Exactly same code piece worked for me - for a collection (of child domain objects) property,
isInitialized()
returnedfalse
and for a String property -true
. MaybeFetchMode.LAZY
is not a guarantee - if you're requesting a simple type, it gets fetched anyway.What is
preferences
' type?