当我在 JDO/DataNucleus 中为聚合函数调用 setResultClass(...) 时,抛出 JDOUserException
使用以下代码
Query query = pm.newQuery(User.class);
query.setFilter( "username == :usernameParam" );
query.setResult( "count(username)" );
query.setResultClass(Long.class);
Object result = query.execute(username);
return (result!=null && (Long)result>0);
我得到这个异常:
javax.jdo.JDOUserException:查询 将返回单个字段,但它是 与 ResultClass (java.lang.Long) :它是 java.lang.Long
如果我删除 .setResult(Long.class)
查询,它会起作用并返回一个 Long。
也许我不理解 setResult()
方法。我知道我需要设置它来指示我想要什么类型的结果。但 count()
这样的聚合函数不就是这种情况吗?
With the following code
Query query = pm.newQuery(User.class);
query.setFilter( "username == :usernameParam" );
query.setResult( "count(username)" );
query.setResultClass(Long.class);
Object result = query.execute(username);
return (result!=null && (Long)result>0);
I get this exception:
javax.jdo.JDOUserException: The Query
will return a single field but it is
not of a consistent type as the
ResultClass (java.lang.Long) : It is
java.lang.Long
If I remove the .setResult(Long.class)
query it works and I get back a Long.
Perhaps I don't understand the setResult()
method. I had understood that I need to set this to indicate what type of result I wanted. But is this not the case with aggregate functions such as count()
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是几天前修复的。幸运的是,2.1.3 和 2.2 M3 版本已在一小时左右发布;-)
That was fixed several days ago. Fortunately for you versions 2.1.3 and 2.2 M3 were released an hour or so ago ;-)