Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 多选NPE中的JPA/Hibernate函数_Java_Hibernate_Jpa_Jpa 2.0 - Fatal编程技术网

Java 多选NPE中的JPA/Hibernate函数

Java 多选NPE中的JPA/Hibernate函数,java,hibernate,jpa,jpa-2.0,Java,Hibernate,Jpa,Jpa 2.0,在multiselect(或select(构造(…)中使用函数会导致NullPointerException(Hibernate 4+)出现以下代码: criteriaQuery.select(criteriaBuilder.construct(OrderCriteria.class, order.get(Order_.id), criteriaBuilder.function("array_to_string", String.class,

在multiselect(或select(构造(…)中使用函数会导致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(",")),
    ));
我将异常追溯到Hibernate ConstructionNode::resolveConstructorArgumentTypes

MethodNode(criteriaBuilder.function创建MethodNode)上似乎不存在getDataType(),导致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;
}
私有类型[]resolveConstructorArgumentTypes()引发语义异常{
SelectExpression[]argumentExpressions=collectSelectExpressions();
if(argumentExpressions==null){
//返回一个空类型数组
返回新类型[]{};
}
类型[]类型=新类型[argumentExpressions.length];
for(int x=0;x[types[x]==null with MethodNode]
}
返回类型;
}

select的构造方式是否有问题?

几个小时后,很明显,无法以这种方式使用未注册的函数,导致此异常非常不清楚

解决方案:

public class ExtendedPostgreSQL9Dialect extends PostgreSQL9Dialect{

    public ExtendedPostgreSQL9Dialect() {
        super();

        registerFunction("array_agg", new StandardSQLFunction("array_agg", StandardBasicTypes.STRING));
    }
}
public class ExtendedPostgreSQL9Dialect extends PostgreSQL9Dialect{

    public ExtendedPostgreSQL9Dialect() {
        super();

        registerFunction("array_agg", new StandardSQLFunction("array_agg", StandardBasicTypes.STRING));
    }
}