【发布时间】:2014-10-04 05:30:27
【问题描述】:
在多选(或 select(construct(...)) 中使用函数会导致 NullPointerException(Hibernate 4+),代码如下:
criteriaQuery.select(criteriaBuilder.construct(OrderCriteria.class,
order.get(Order_.id),
criteriaBuilder.function("array_to_string", String.class,
criteriaBuilder.function("array_agg", String.class, employee.<String>get(Employee_.firstName)), criteriaBuilder.literal(",")),
));
抛出以下异常:
java.lang.NullPointerException
org.hibernate.internal.util.ReflectHelper.getConstructor(ReflectHelper.java:354)
org.hibernate.hql.internal.ast.tree.ConstructorNode.resolveConstructor(ConstructorNode.java:185)
我已将异常追溯到 Hibernate ConstructionNode::resolveConstructorArgumentTypes。
似乎 getDataType() 在 MethodeNode 上不存在(criteriaBuilder.function 创建一个 MethodNode)导致 NPE:
private Type[] resolveConstructorArgumentTypes() throws SemanticException {
SelectExpression[] argumentExpressions = collectSelectExpressions();
if ( argumentExpressions == null ) {
// return an empty Type array
return new Type[] {};
}
Type[] types = new Type[argumentExpressions.length];
for ( int x = 0; x < argumentExpressions.length; x++ ) {
types[x] = argumentExpressions[x].getDataType(); --> [types[x] == null with MethodNode]
}
return types;
}
select 的构造方式有问题吗?
【问题讨论】:
标签: java hibernate jpa jpa-2.0