|
我知道这个问题已经提出了很多,但是我似乎遇到了一个不同的问题。我看到Hibernate中有一个错误,该错误与SumFunction忽略了自定义用户类型有关,但据我所知,我没有使用自定义用户类型。我基本上是试图创建一个新对象,该对象是现有映射bean的汇总,但是我收到了NullPointerException针对某些Hibernate方言函数的。我尝试将Double和BigDecimal都用作value字段类型,但在部署时都向我提供了相同的错误消息。请帮忙!
2 O5 a9 n2 \9 `+ u/ @# G' k! X这是一些代码:) p! g8 p. G0 V- a; [1 _
映射的豆:* j" @3 E3 @( W7 H. d- E8 R- N
@Entity
3 Q% k, ?7 k! ~0 O2 r@Table(name = "v_summary_report")" p% y5 M! t( Y0 m; w
public class SummaryReportView implements java.io.Serializable {; t6 ~/ m; b/ `9 t
private static final long serialVersionUID = 1L;: H. s' g6 q: v# j3 }7 |! ]
@Id
Q' p. j/ \: }" z @Column(name = "id")
- F/ W- b& I3 w private String id;( J/ c. [6 ~% W8 F0 g+ `& r
@Column(name = "region"); Z3 F, ~6 B0 g
private String region; F7 b$ i; y3 K& n
@Column(name = "market")
) ]+ ?2 _/ v% r" T( |& ~& ~ R0 f private String market;
* X3 ]! \8 c5 B ^# g3 B9 P/ m* O @Column(name = "proj_year_month")/ H2 }9 ]' s1 W$ E% l) c. P
private String projectionYearMonth;
* ^2 \% ?6 l3 B+ r0 |! e @OneToOne(cascade={CascadeType.DETACH})
- K; ^: s5 p* r7 P7 x" f3 w @JoinColumn(name="attrib_id", referencedColumnName="attrib_id")" w5 {3 i V0 o
private Attribute attribute;; ]! r- H3 U8 J, G- }, N; R( g2 T: I
@Column(name = "total_value")
0 `, ? A8 m7 c1 D private BigDecimal value;+ C+ P' _5 U- Y7 k( T) H2 k; ^
/* other stuff */
* y: O5 f5 X! L2 x4 x7 \" s}
2 \* y2 |& X i2 A! t7 ^命名查询被调用:
9 l; }) q j/ D# S# [8 a @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"),
) b' W9 @+ w, }- a3 k/ E( CBean总定义:
% F# B7 C8 }- [public class SummaryReportTotal {. s# l$ j/ h2 n# F! q* z
private String projectionYearMonth;
( D) D$ n4 x3 w5 M: c private Attribute attribute;
, B+ x% k/ [" }, Y private BigDecimal value;) L0 l ]% d, I' U
public SummaryReportTotal() {
. k% e* _4 S6 N# Q3 b3 o; j super();
$ V. j% T7 y$ V: X- t3 x0 K }" f3 d- d" U, [
public SummaryReportTotal(String projectionYearMonth, Attribute attribute, BigDecimal value) {! r# d! E1 y, c' k) P
this.projectionYearMonth = projectionYearMonth;" ^4 u- X! ]- }! D
this.attribute = attribute;! ]' ?; Y5 f) p0 d' E
this.value = value;' U, J; A. Y- d; l1 y; K9 I5 A' i
}
8 k" {$ N) K. q: d. V /* other stuff */, J0 Z( D, f! W- g+ i0 x4 G/ @
}- s+ i0 p% e; P; n
堆栈跟踪 :
# n/ p' l% R) c0 x' F' QCaused by: java.lang.NullPointerException
! X! {- i8 ^1 F! N- Sat org.hibernate.dialect.function.StandardAnsiSqlAggregationFunctions$SumFunction.determineJdbcTypeCode(StandardAnsiSqlAggregationFunctions.java:145)! Q" j* l' n" K0 R/ t9 C c
at org.hibernate.dialect.function.StandardAnsiSqlAggregationFunctions$SumFunction.getReturnType(StandardAnsiSqlAggregationFunctions.java:157)
3 g4 Q8 G6 Q/ ~% a/ e b. Vat org.hibernate.hql.internal.ast.util.SessionFactoryHelper.findFunctionReturnType(SessionFactoryHelper.java:406); w; g8 {! e$ w4 v1 |+ t5 F) R( I
at org.hibernate.hql.internal.ast.tree.AggregateNode.getDataType(AggregateNode.java:83)6 d J: L. M4 G8 Y5 C
at org.hibernate.hql.internal.ast.tree.ConstructorNode.resolveConstructorArgumentTypes(ConstructorNode.java:166)
" [) t/ ~) U+ w0 }: ^at org.hibernate.hql.internal.ast.tree.ConstructorNode.prepare(ConstructorNode.java:141)* H4 K- R6 R- v
at org.hibernate.hql.internal.ast.HqlSqlWalker.processConstructor(HqlSqlWalker.java:1019)
o) J. f" l. h) z1 X" B( p& lat org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:2150)$ _0 G# t$ ]- T# u( c
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:2016)7 A k3 Q: ~' q# t0 n/ b
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1451)7 F( S. E [5 U8 f7 m: W S& g' c
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:571)! Q& Q* e" ?% x; a* T
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299)
% u: V8 U8 \0 Lat org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247)* y& t0 l' h2 D! e, {3 B
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248)
- p+ x- U% p/ s' \6 fat org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
3 j. q* w2 r2 \# S* q0 c. j' lat org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
. ]7 `% Y9 v6 W3 w6 K- Bat org.hibernate.engine.query.spi.HQLQueryPlan.<i>(HQLQueryPlan.java:105)
8 J/ Y1 B# ?5 _( gat org.hibernate.engine.query.spi.HQLQueryPlan.<i>(HQLQueryPlan.java:80)5 Z3 [3 a! L6 M( @
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168): `* C$ j7 M) p% M! o: M9 Q- V
at org.hibernate.internal.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:1032)- J$ I2 |3 t) T( P) }
at org.hibernate.internal.SessionFactoryImpl.<i>(SessionFactoryImpl.java:506)
; M- R; A% M+ B+ qat org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750)
: \7 B2 r5 x- V* ^/ ^! p+ U# Rat org.hibernate.ejb.EntityManagerFactoryImpl.<i>(EntityManagerFactoryImpl.java:94)
- F$ q0 W2 p( Xat org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)+ x8 b C9 `! x9 A+ Q2 u2 t8 W5 c( S9 v
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)
* V7 W+ |+ y, U/ Gat org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
: f6 {$ p8 j# k& i0 hat org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225): N8 M2 T& [8 O$ z5 w4 |3 u0 `
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
3 x* w, Z H9 i8 H. J8 j9 l, Zat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)5 J, ]1 z1 V, G/ S5 u$ a I
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)1 E. B* \4 [) d! Y/ V
... 45 more2 x( ^+ O( O1 P) O
: j5 E' n# @7 o2 Z. V! C/ J! G; G解决方案:" o0 e9 B, b( n7 O. ?0 j2 S. ^
, ~: t1 w% G' w
, ` Z# H9 k4 V; O
, m. p3 n3 O* k0 r9 } 如果value以表别名作为前缀,我不会感到惊讶,因为其他字段可以解决该问题 7 N( z2 y. d# B( I5 a* \
... sum(srv.value) ...
2 f' l/ h5 g1 ^9 n* @有时,HQL解析器在解析步骤中将标识符解析为有效,但是在执行期间会因奇怪的异常而失败。 |
|