本文介绍了HQL的新对象 - StandardAnsiSqlAggregationFunctions的NPE,determineJdbcTypeCode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这已被,但我似乎有一个不同的问题。我发现在Hibernate中存在一个,该命令与SumFunction一起工作,忽略了自定义用户类型,但我没有使用自定义用户类型,据我所知。我基本上试图创建一个新的对象,它是现有映射Bean的汇总,但是我收到了一个针对某些Hibernate方言函数的 NullPointerException 。我尝试使用Double和BigDecimal作为我的字段类型,但两者在部署时都提供了相同的错误消息。请帮忙!



以下是一些代码:

映射的bean:

  @Entity 
@Table(name =v_summary_report)
public class SummaryReportView实现java.io.Serializable {

private static final long serialVersionUID = 1L;

@Id
@Column(name =id)
私人字符串ID;

@Column(name =region)
private String region;

@Column(name =market)
私人字符串市场;

@Column(name =proj_year_month)
private String projectionYearMonth;

@OneToOne(cascade = {CascadeType.DETACH})
@JoinColumn(name =attrib_id,referencedColumnName =attrib_id)
私有属性属性;

@Column(name =total_value)
私人BigDecimal值;

/ *其他东西* /
}

命名查询被称为:

  @NamedQuery(name =findSummaryReportTotalByRegion,query =SELECT new com.rac.projections.bean.SummaryReportTotal (srv.projectionYearMonth,srv.attribute,sum(value))from SummaryReportView srv where srv.region =:region group by srv.projectionYearMonth,srv.attribute),

总的bean定义:

  public class SummaryReportTotal {

private String projectionYearMonth;
私有属性属性;
私人BigDecimal值;

public SummaryReportTotal(){
super();
}

public SummaryReportTotal(String projectionYearMonth,Attribute attribute,BigDecimal value){
this.projectionYearMonth = projectionYearMonth;
this.attribute =属性;
this.value = value;
}

/ *其他东西* /
}

Stacktrace:

 由org.hibernate.dialect.function引发java.lang.NullPointerException 
。 StandardAnsiSqlAggregationFunctions $ SumFunction.determineJdbcTypeCode(StandardAnsiSqlAggregationFunctions.java:145)
at org.hibernate.dialect.function.StandardAnsiSqlAggregationFunctions $ SumFunction.getReturnType(StandardAnsiSqlAggregationFunctions.java:157)
at org.hibernate.hql.internal。 ast.util.SessionFactoryHelper.findFunctionReturnType(SessionFactoryHelper.java:406)
at org.hibernate.hql.internal.ast.tree.AggregateNode.getDataType(AggregateNode.java:83)
org.hibernate。 hql.internal.ast.tree.ConstructorNode.resolveConstructorArgumentTypes(ConstructorNode.java:166)
at org.hibernate.hql.internal.ast.tree.ConstructorNode.prepare(ConstructorNode.java:141)
at org.hibernate.hql.internal.ast.HqlSqlWalker.processConstructor(HqlSqlWalker.java:1019)
org。 hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:2150)
在org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:2016)
。在组织。 hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1451)
在org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:571)
。在组织。 hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299)
在org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247)
。在组织。 hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248)
在org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
。在组织。 hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
位于org.hibernate.engine.query.spi.HQLQueryPlan。< init>(HQLQueryPlan.java:105)
在org.hibernate.engine.query.spi.HQLQuery < init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
at org.hibernate.internal.SessionFactoryImpl .checkNamedQueries(SessionFactoryImpl.java:1032)
at org.hibernate.internal.SessionFactoryImpl。< init>(SessionFactoryImpl.java:506)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration。的java:1750)
。在org.hibernate.ejb.EntityManagerFactoryImpl< INIT>(EntityManagerFactoryImpl.java:94)
。在org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)$。 b $ b。在org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)
处org.springframework org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
。 orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
at org.springframewor在org.springframework处
。org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods($ AbstractAutowireCapableBeanFactory.java:1477)
在org.springframework。
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework。 beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 45 more


解决方案

如果在其他字段使用表别名前缀 value 将解决问题,我不会感到惊讶

  ... sum(srv.value)... 

有时HQL解析器在解析步骤中将解析标识符解析为有效,但在执行期间会出现奇怪的异常。查看


I know this has been asked a lot, but I seem to be having a different problem. I saw that there is a bug in Hibernate that struggles with a SumFunction ignoring custom user types, but I'm not using a custom user type to my knowledge. I'm basically trying to create a new object that is a roll-up of an existing mapping bean, however I receive a NullPointerException against some Hibernate dialect function. I tried using both Double and BigDecimal as my value field type, but both provide me the same error message on deployment. Please help!

Here's some code:

Mapped bean:

@Entity
@Table(name = "v_summary_report")
public class SummaryReportView implements java.io.Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "id")
    private String id;

    @Column(name = "region")
    private String region;

    @Column(name = "market")
    private String market;

    @Column(name = "proj_year_month")
    private String projectionYearMonth;

    @OneToOne(cascade={CascadeType.DETACH})
    @JoinColumn(name="attrib_id", referencedColumnName="attrib_id")
    private Attribute attribute;

    @Column(name = "total_value")
    private BigDecimal value;

    /* other stuff */
}

Named query being called:

    @NamedQuery(name = "findSummaryReportTotalByRegion", query = " SELECT new com.rac.projections.bean.SummaryReportTotal(srv.projectionYearMonth, srv.attribute, sum(value)) from SummaryReportView srv where srv.region = :region group by srv.projectionYearMonth, srv.attribute"),

Total bean definition:

public class SummaryReportTotal {

    private String projectionYearMonth;
    private Attribute attribute;
    private BigDecimal value;

    public SummaryReportTotal() {
        super();
    }

    public SummaryReportTotal(String projectionYearMonth, Attribute attribute, BigDecimal value) {
        this.projectionYearMonth = projectionYearMonth;
        this.attribute = attribute;
        this.value = value;
    }

    /* other stuff */
}

Stacktrace :

Caused by: java.lang.NullPointerException
at org.hibernate.dialect.function.StandardAnsiSqlAggregationFunctions$SumFunction.determineJdbcTypeCode(StandardAnsiSqlAggregationFunctions.java:145)
at org.hibernate.dialect.function.StandardAnsiSqlAggregationFunctions$SumFunction.getReturnType(StandardAnsiSqlAggregationFunctions.java:157)
at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.findFunctionReturnType(SessionFactoryHelper.java:406)
at org.hibernate.hql.internal.ast.tree.AggregateNode.getDataType(AggregateNode.java:83)
at org.hibernate.hql.internal.ast.tree.ConstructorNode.resolveConstructorArgumentTypes(ConstructorNode.java:166)
at org.hibernate.hql.internal.ast.tree.ConstructorNode.prepare(ConstructorNode.java:141)
at org.hibernate.hql.internal.ast.HqlSqlWalker.processConstructor(HqlSqlWalker.java:1019)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:2150)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:2016)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1451)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:571)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:105)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
at org.hibernate.internal.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:1032)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:506)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 45 more
解决方案

I will not be surprised if prefixing value with table alias as other fields will resolve the problem

... sum(srv.value) ...

Sometimes HQL parser resolve identifier as valid during parsing step, but fails with strange exception during execution. Look here

这篇关于HQL的新对象 - StandardAnsiSqlAggregationFunctions的NPE,determineJdbcTypeCode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 18:28