我知道这已经被问了很多,但我似乎有一个不同的问题。我看到 Hibernate 中有一个错误,它与 SumFunction 忽略自定义用户类型作斗争,但据我所知,我没有使用自定义用户类型。我基本上是在尝试创建一个新对象,它是现有映射 bean 的汇总,但是我收到了一个NullPointerException
针对某些 Hibernate 方言函数的结果。我尝试使用 Double 和 BigDecimal 作为我的value
字段类型,但两者都在部署时为我提供了相同的错误消息。请帮忙!
这是一些代码:
映射的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 */
}
被调用的命名查询:
@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;
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 */
}
堆栈跟踪 :
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