java.lang.NullPointerException at org.hibernate.hql.internal.NameGenerator.generateColumnNames(NameGenerator.java:27)

huangapple go评论69阅读模式
英文:

java.lang.NullPointerException at org.hibernate.hql.internal.NameGenerator.generateColumnNames(NameGenerator.java:27)

问题

这个问题看起来是一个Java Hibernate的异常,具体是"java.lang.NullPointerException"。它似乎与查询中的某些配置有关。你可能需要检查你的Criteria查询和实体映射是否正确配置,以确保它们符合预期。如果你能提供更多关于你的数据模型和查询的信息,我可能能够提供更具体的帮助。

英文:

I have a problem while doing the CriteriaAPI multiselect from Join using the CriteriaBuilder.function ("group_concat") with the following entities and queries:

CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery<RegistryGroupRow> c = cb.createQuery(RegistryGroupRow.class);
    Root<RegistryGroupEntity> registryGroup = c.from(RegistryGroupEntity.class);

    Join<RegistryGroupEntity, ServiceEntity> serviceJoin = registryGroup.join(RegistryGroupEntity_.services, JoinType.INNER);

    c.multiselect(registryGroup.get(RegistryGroupEntity_.id),
            registryGroup.get(RegistryGroupEntity_.name),
            cb.function("group_concat", String.class, serviceJoin.get(ServiceEntity_.name), cb.literal(true),
                    cb.literal(", "), serviceJoin.get(ServiceEntity_.name),
                    cb.literal("DESC")).alias("name"));
    c.where().groupBy(registryGroup.get(RegistryGroupEntity_.name));
    c.orderBy(cb.desc(registryGroup.get(RegistryGroupEntity_.id)));

    List<Predicate> criteria = getRegistryGroupPredicates(cb, registryGroup, filter, c);
    if (criteria.size() == 1) {
        c.where(criteria.get(0));
    } else if (criteria.size() > 0) {
        c.where(cb.and(criteria.toArray(new Predicate[0])));
    }

    TypedQuery<RegistryGroupRow> q = entityManager.createQuery(c);
    Map<String, Object> paramValues = getRegistryGroupParamValues(filter);
    for (String name : paramValues.keySet()) {
        q.setParameter(name, paramValues.get(name));
    }

    if (offset != null) {
        q.setFirstResult(offset);
    }
    if (limit != null) {
        q.setMaxResults(limit);
    }

    return q.getResultList();


@Entity
@Table(name = "registry_groups")
public class RegistryGroupEntity {
    @Id
    @SequenceGenerator(name="registry_groups_gen", sequenceName="registry_groups_id_seq", allocationSize = 1)
    @GeneratedValue(generator="registry_groups_gen")
    private Integer id;
    @Column(name = "name")
    private String name;

    @OneToMany(mappedBy = "registryGroup")
    private Collection<ServiceEntity> services;
//setters-getters ommited
}

@Entity
@Table(name = "services")
public class ServiceEntity {
    @Id
    @SequenceGenerator(name="service_gen", sequenceName="services_id_seq", allocationSize = 1)
    @GeneratedValue(generator="service_gen")
    private Integer id;
    @Column(nullable = false, length = 100)
    private String name;

    @Column(name = "registry_group_id", insertable = false, updatable = false)
    private Integer registryGroupId;

}

So, when the query is executed, it fails with:

SEVERE: 
java.lang.NullPointerException
	at org.hibernate.hql.internal.NameGenerator.generateColumnNames(NameGenerator.java:27)
	at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.generateColumnNames(SessionFactoryHelper.java:418)
	at org.hibernate.hql.internal.ast.tree.SelectClause.initializeColumnNames(SelectClause.java:269)
	at org.hibernate.hql.internal.ast.tree.SelectClause.finishInitialization(SelectClause.java:259)
	at org.hibernate.hql.internal.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:254)
	at org.hibernate.hql.internal.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:1011)
	at org.hibernate.hql.internal.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:779)
	at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:675)
	at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:311)
	at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:259)
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:261)
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:189)
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:141)
	at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:115)
	at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
	at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:153)
	at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:545)
	at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:654)
	at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:3307)
	at org.hibernate.query.criteria.internal.CriteriaQueryImpl$1.buildCompiledQuery(CriteriaQueryImpl.java:318)
	at org.hibernate.query.criteria.internal.compile.CriteriaCompiler.compile(CriteriaCompiler.java:127)
	at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:3600)
	at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:203)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:301)
	at com.sun.proxy.$Proxy111.createQuery(Unknown Source)
	at com.openpayment.impl.dao.RegistryGroupDaoImpl.getRegistryGroupRows(RegistryGroupDaoImpl.java:247)
	at com.openpayment.impl.service.RegistryGroupServiceImpl.getRegistryGroupRows(RegistryGroupServiceImpl.java:67)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
	at org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:69)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:283)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
	at com.sun.proxy.$Proxy174.getRegistryGroupRows(Unknown Source)
	at com.openpayment.web.view.registry.RegistryGroupView.lambda$buildTable$7f718060$1(RegistryGroupView.java:167)
	at com.vaadin.data.provider.CallbackDataProvider.fetchFromBackEnd(CallbackDataProvider.java:137)
	at com.vaadin.data.provider.AbstractBackEndDataProvider.fetch(AbstractBackEndDataProvider.java:61)
	at com.vaadin.data.provider.DataCommunicator.fetchItemsWithRange(DataCommunicator.java:404)
	at com.vaadin.data.provider.DataCommunicator.sendDataToClient(DataCommunicator.java:377)
	at com.vaadin.data.provider.DataCommunicator.beforeClientResponse(DataCommunicator.java:339)
	at com.vaadin.server.communication.UidlWriter.write(UidlWriter.java:126)
	at com.vaadin.server.communication.UidlRequestHandler.writeUidl(UidlRequestHandler.java:124)
	at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:92)
	at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
	at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1606)
	at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:448)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:835)

In

generateColumnNames:25, NameGenerator (org.hibernate.hql.internal)
generateColumnNames:418, SessionFactoryHelper (org.hibernate.hql.internal.ast.util)
initializeColumnNames:269, SelectClause (org.hibernate.hql.internal.ast.tree)
finishInitialization:259, SelectClause (org.hibernate.hql.internal.ast.tree)
initializeExplicitSelectClause:254, SelectClause (org.hibernate.hql.internal.ast.tree)
useSelectClause:1011, HqlSqlWalker (org.hibernate.hql.internal.ast)
processQuery:779, HqlSqlWalker (org.hibernate.hql.internal.ast)
query:675, HqlSqlBaseWalker (org.hibernate.hql.internal.antlr)
selectStatement:311, HqlSqlBaseWalker (org.hibernate.hql.internal.antlr)
statement:259, HqlSqlBaseWalker (org.hibernate.hql.internal.antlr)
analyze:261, QueryTranslatorImpl (org.hibernate.hql.internal.ast)
doCompile:189, QueryTranslatorImpl (org.hibernate.hql.internal.ast)
compile:141, QueryTranslatorImpl (org.hibernate.hql.internal.ast)
<init>:115, HQLQueryPlan (org.hibernate.engine.query.spi)
<init>:77, HQLQueryPlan (org.hibernate.engine.query.spi)
getHQLQueryPlan:153, QueryPlanCache (org.hibernate.engine.query.spi)
getQueryPlan:545, AbstractSharedSessionContract (org.hibernate.internal)
createQuery:654, AbstractSharedSessionContract (org.hibernate.internal)
createQuery:3307, SessionImpl (org.hibernate.internal)
buildCompiledQuery:318, CriteriaQueryImpl$1 (org.hibernate.query.criteria.internal)
compile:127, CriteriaCompiler (org.hibernate.query.criteria.internal.compile)
createQuery:3600, SessionImpl (org.hibernate.internal)
createQuery:203, SessionImpl (org.hibernate.internal)
invoke0:-1, NativeMethodAccessorImpl (jdk.internal.reflect)
invoke:62, NativeMethodAccessorImpl (jdk.internal.reflect)
invoke:43, DelegatingMethodAccessorImpl (jdk.internal.reflect)
invoke:567, Method (java.lang.reflect)
invoke:301, SharedEntityManagerCreator$SharedEntityManagerInvocationHandler (org.springframework.orm.jpa)
createQuery:-1, $Proxy111 (com.sun.proxy)
getRegistryGroupRows:247, RegistryGroupDaoImpl (com.openpayment.impl.dao)
getRegistryGroupRows:67, RegistryGroupServiceImpl (com.openpayment.impl.service)
invoke0:-1, NativeMethodAccessorImpl (jdk.internal.reflect)
invoke:62, NativeMethodAccessorImpl (jdk.internal.reflect)
invoke:43, DelegatingMethodAccessorImpl (jdk.internal.reflect)
invoke:567, Method (java.lang.reflect)
invokeJoinpointUsingReflection:333, AopUtils (org.springframework.aop.support)
invokeJoinpoint:190, ReflectiveMethodInvocation (org.springframework.aop.framework)
proceed:157, ReflectiveMethodInvocation (org.springframework.aop.framework)
invoke:69, MethodSecurityInterceptor (org.springframework.security.access.intercept.aopalliance)
proceed:179, ReflectiveMethodInvocation (org.springframework.aop.framework)
proceedWithInvocation:99, TransactionInterceptor$1 (org.springframework.transaction.interceptor)
invokeWithinTransaction:283, TransactionAspectSupport (org.springframework.transaction.interceptor)
invoke:96, TransactionInterceptor (org.springframework.transaction.interceptor)
proceed:179, ReflectiveMethodInvocation (org.springframework.aop.framework)
invoke:213, JdkDynamicAopProxy (org.springframework.aop.framework)
getRegistryGroupRows:-1, $Proxy174 (com.sun.proxy)
lambda$buildTable$7f718060$1:167, RegistryGroupView (com.openpayment.web.view.registry)
fetch:-1, 1332458831 (com.openpayment.web.view.registry.RegistryGroupView$$Lambda$332)
fetchFromBackEnd:137, CallbackDataProvider (com.vaadin.data.provider)
fetch:61, AbstractBackEndDataProvider (com.vaadin.data.provider)
fetchItemsWithRange:404, DataCommunicator (com.vaadin.data.provider)
sendDataToClient:377, DataCommunicator (com.vaadin.data.provider)
beforeClientResponse:339, DataCommunicator (com.vaadin.data.provider)
write:126, UidlWriter (com.vaadin.server.communication)
writeUidl:124, UidlRequestHandler (com.vaadin.server.communication)
synchronizedHandleRequest:92, UidlRequestHandler (com.vaadin.server.communication)
handleRequest:40, SynchronizedRequestHandler (com.vaadin.server)
handleRequest:1606, VaadinService (com.vaadin.server)
service:448, VaadinServlet (com.vaadin.server)
service:728, HttpServlet (javax.servlet.http)
internalDoFilter:305, ApplicationFilterChain (org.apache.catalina.core)
doFilter:210, ApplicationFilterChain (org.apache.catalina.core)
doFilter:51, WsFilter (org.apache.tomcat.websocket.server)
internalDoFilter:243, ApplicationFilterChain (org.apache.catalina.core)
doFilter:210, ApplicationFilterChain (org.apache.catalina.core)
invoke:222, StandardWrapperValve (org.apache.catalina.core)
invoke:123, StandardContextValve (org.apache.catalina.core)
invoke:502, AuthenticatorBase (org.apache.catalina.authenticator)
invoke:171, StandardHostValve (org.apache.catalina.core)
invoke:100, ErrorReportValve (org.apache.catalina.valves)
invoke:953, AccessLogValve (org.apache.catalina.valves)
invoke:118, StandardEngineValve (org.apache.catalina.core)
service:408, CoyoteAdapter (org.apache.catalina.connector)
process:1041, AbstractHttp11Processor (org.apache.coyote.http11)
process:603, AbstractProtocol$AbstractConnectionHandler (org.apache.coyote)
run:312, JIoEndpoint$SocketProcessor (org.apache.tomcat.util.net)
runWorker:1128, ThreadPoolExecutor (java.util.concurrent)
run:628, ThreadPoolExecutor$Worker (java.util.concurrent)
run:835, Thread (java.lang)

it has been turned out, that Types array is a size of 3, but have only two values, the Integer one and the String one.

java.lang.NullPointerException at org.hibernate.hql.internal.NameGenerator.generateColumnNames(NameGenerator.java:27)

答案1

得分: 1

已经证明,Types数组的大小为3,但只有两个值,一个是整数,一个是字符串。

英文:

it has been turned out, that Types array is a size of 3, but vae only two values, the Integer one and the String one.

huangapple
  • 本文由 发表于 2023年4月13日 20:18:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76005348.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定