[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2833?page=c...
]
John Mazzitelli commented on HHH-2833:
--------------------------------------
more information - using the eclipse hibernate tools (which uses 3.2.0.rc4 of
hibernate3.jar, as per the manifest info found in
plugins\org.hibernate.eclipse_3.2.0.beta8\lib\hibernate\hibernate3.jar), I can see the
generated native SQL produced - no NPE occurs.
But if i use 3.2.3.GA, and use basically the same APIs as the eclipse tools do to compile
the hql, this results in the NPE:
String hqlQueryString = ...my insert select HQL query as described in this jira...
SessionFactoryImplementor sf = ...
new HQLQueryPlan(hqlQueryString, false, Collections.EMPTY_MAP, sf); // throws NPE
It appears based on this crude testing of mine, that something broke between 3.2.0 and
3.2.3.
BTW: I'll won't be able to get a runnable test - the domain model is not trivial -
I'd have to spend a day just to strip things out and package it up to be a runnable
standalone. JBoss employees will have access to my code, since its accessible via SVN
(albeit via VPN) - contact me if you want to see it run.
NullPointerException in insert-select query
-------------------------------------------
Key: HHH-2833
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2833
Project: Hibernate3
Issue Type: Bug
Components: query-hql
Affects Versions: 3.2.3
Reporter: John Mazzitelli
I'm getting the following NPE when I convert a valid SELECT query into an INSERT
SELECT query.
Here's the stack:
==================================================
Caused by: java.lang.NullPointerException
at
org.hibernate.hql.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:310)
at
org.hibernate.hql.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3275)
at
org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3067)
at
org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
at
org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
at
org.hibernate.hql.antlr.HqlSqlBaseWalker.insertStatement(HqlSqlBaseWalker.java:482)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:253)
at
org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
at
org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at
org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at
org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at
org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at
org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at
org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:92)
at
org.jboss.ejb3.entity.TransactionScopedEntityManager.createQuery(TransactionScopedEntityManager.java:127)
at
org.jboss.on.domain.util.PersistenceUtility.createInsertSelectQuery(PersistenceUtility.java:225)
at
org.jboss.on.server.measurement.MeasurementBaselineManagerBean.calculateAutoBaselines(MeasurementBaselineManagerBean.java:80)
... 60 more
==================================================
I first start out with this valid SELECT query (I can run this in the Hibernate Tools in
Eclipse - it works and returns valid data as expected):
----------
SELECT
min(d.min) AS baselineMin,
max(d.max) AS baselineMax,
avg(d.value) AS baselineMean,
CURRENT_TIMESTAMP AS computeTime,
d.id.scheduleId AS scheduleId
FROM
MeasurementDataNumeric1H d
JOIN
d.schedule s
LEFT JOIN
s.baseline b
WHERE
b.id IS NULL
AND d.id.timestamp BETWEEN :startTime AND :endTime
GROUP BY
d.id.scheduleId
HAVING
d.id.scheduleId IN (
SELECT
d1.id.scheduleId
FROM
MeasurementDataNumeric1H d1
WHERE
d1.id.timestamp <= :startTime
)
----------
Here is what the Hibernate Tools Dynamic SQL Preview view shows me is the actual,
generated SQL:
----------
select
min(measuremen0_.minvalue) as col_0_0_,
max(measuremen0_.maxvalue) as col_1_0_,
avg(measuremen0_.value) as col_2_0_,
CURRENT_TIMESTAMP as col_3_0_,
measuremen0_.SCHEDULE_ID as col_4_0_
from
public.ON_MEASUREMENT_DATA_NUM_1H measuremen0_
inner join
public.ON_MEASUREMENT_SCHEDULE measuremen1_
on measuremen0_.SCHEDULE_ID=measuremen1_.id
left outer join
public.ON_MEASUREMENT_BASELINE measuremen2_
on measuremen1_.id=measuremen2_.SCHEDULE_ID
where
(
measuremen2_.id is null
)
and (
measuremen0_.TIME_STAMP between ? and ?
)
group by
measuremen0_.SCHEDULE_ID
having
measuremen0_.SCHEDULE_ID in (
select
measuremen3_.SCHEDULE_ID
from
public.ON_MEASUREMENT_DATA_NUM_1H measuremen3_
where
measuremen3_.TIME_STAMP<=?
)
----------
Now that I can see this works, I simply add this line to the beginning of that SELECT
query:
----------
INSERT INTO MeasurementBaseline
(baselineMin,baselineMax,baselineMean,computeTime,scheduleId)
----------
Here is what the Hibernate Tools Dynamic SQL Preview view shows me is the actual,
generated SQL:
----------
insert
into
public.ON_MEASUREMENT_BASELINE
( id, BL_MIN, BL_MAX, BL_MEAN, BL_COMPUTE_TIME, SCHEDULE_ID )
select
nextval ('public.ON_MEASUREMENT_BASELINE_ID_SEQ'),
min(measuremen0_.minvalue) as col_0_0_,
max(measuremen0_.maxvalue) as col_1_0_,
avg(measuremen0_.value) as col_2_0_,
CURRENT_TIMESTAMP as col_3_0_,
measuremen0_.SCHEDULE_ID as col_4_0_
from
public.ON_MEASUREMENT_DATA_NUM_1H measuremen0_
inner join
public.ON_MEASUREMENT_SCHEDULE measuremen1_
on measuremen0_.SCHEDULE_ID=measuremen1_.id
left outer join
public.ON_MEASUREMENT_BASELINE measuremen2_
on measuremen1_.id=measuremen2_.SCHEDULE_ID
where
(
measuremen2_.id is null
)
and (
measuremen0_.TIME_STAMP between ? and ?
)
group by
measuremen0_.SCHEDULE_ID
having
measuremen0_.SCHEDULE_ID in (
select
measuremen3_.SCHEDULE_ID
from
public.ON_MEASUREMENT_DATA_NUM_1H measuremen3_
where
measuremen3_.TIME_STAMP<=?
)
----------
If I were to pass in the HQL (the INSERT INTO...SELECT) via:
entityManager.createQuery("INSERT INTO...SELECT...and the rest...")
I get the NPE.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira