1

1つの関数で以下のクエリを実行していますが、「SQLGrammarException:ネイティブバルク操作クエリエラーを実行できませんでした」という例外が発生します。

誰かが私にそれの解決策を教えてもらえますか?HQLは使いたくない。

    query = session.createSQLQuery("CREATE TEMPORARY TABLE temp select `"+xAxis+"`, sum(value) as length from (select * from "+xAxis+"Table union select `"+xAxis+"`, sum(cycles) as value from "+Constants.TABLE_NAME+" where datestamp >= '"+startDate+"'  and datestamp < '"+endDate+"'  and `"+groupBy+"` = '"+groupByBar1+"' and `"+xAxis+"` = 'Uptime' group by `"+xAxis+"`) as t group by `"+xAxis+"` "+fixOrderString+" ;CREATE TEMPORARY TABLE test select `"+xAxis+"`, sum(value) as length from (select * from "+xAxis+"Table union select `"+xAxis+"`, sum(cycles) as value from "+Constants.TABLE_NAME+" where datestamp >= '"+startDate+"'  and datestamp < '"+endDate+"' and  `"+xAxis+"` = 'Uptime' group by `"+xAxis+"`) as t group by `"+xAxis+"` "+fixOrderString+" ;alter table test add column `"+groupByBar1+"` INTEGER ;");  
            query.executeUpdate();              
            query = session.createSQLQuery("update test,temp set `"+groupByBar1+"` = temp.length where test.`"+xAxis+"` = temp.`"+xAxis+"` ; drop table temp ; CREATE TEMPORARY TABLE temp select `"+xAxis+"`, sum(value) as length from (select * from "+xAxis+"Table union select `"+xAxis+"`, sum(cycles) as value from "+Constants.TABLE_NAME+" where datestamp >= '"+startDate+"'  and datestamp < '"+endDate+"' and  `"+groupBy+"` = '"+groupByBar2+"' and `"+xAxis+"` = 'Uptime' group by `"+xAxis+"`) as t group by `"+xAxis+"` "+fixOrderString+"  ;alter table test add column `"+groupByBar2+"` INTEGER ; ");
            query.executeUpdate();
            query = session.createSQLQuery("update test,temp set `"+groupByBar2+"` = temp.length where test.`"+xAxis+"` = temp.`"+xAxis+"` ; drop table temp ; CREATE TEMPORARY TABLE temp select `"+xAxis+"`, sum(value) as length from (select * from "+xAxis+"Table union select `"+xAxis+"`, sum(cycles) as value from "+Constants.TABLE_NAME+" where datestamp >= '"+startDate+"'  and datestamp < '"+endDate+"' and  `"+groupBy+"` = '"+groupByBar3+"' and `"+xAxis+"` = 'Uptime' group by `"+xAxis+"`) as t group by `"+xAxis+"` "+fixOrderString+"  ;alter table test add column `"+groupByBar3+"` INTEGER ;");
            query.executeUpdate();
            query = session.createSQLQuery("update test,temp set `"+groupByBar3+"` = temp.length where test.`"+xAxis+"` = temp.`"+xAxis+"` ; drop table temp ; CREATE TEMPORARY TABLE temp select `"+xAxis+"`, sum(value) as length from (select * from "+xAxis+"Table union select `"+xAxis+"`, sum(cycles) as value from "+Constants.TABLE_NAME+" where datestamp >= '"+startDate+"'  and datestamp < '"+endDate+"' and  `"+groupBy+"` = '"+groupByBar4+"' and `"+xAxis+"` = 'Uptime' group by `"+xAxis+"`) as t group by `"+xAxis+"` "+fixOrderString+"  ;alter table test add column `"+groupByBar4+"` INTEGER ;");
            query.executeUpdate();
            query = session.createSQLQuery("update test,temp set `"+groupByBar4+"` = temp.length where test.`"+xAxis+"` = temp.`"+xAxis+"` ; drop table temp ; CREATE TEMPORARY TABLE temp select `"+xAxis+"`, sum(value) as length from (select * from "+xAxis+"Table union select `"+xAxis+"`, sum(cycles) as value from "+Constants.TABLE_NAME+" where datestamp >= '"+startDate+"'  and datestamp < '"+endDate+"' and  `"+groupBy+"` = `"+Constants.OTHERS+"' and `"+xAxis+"` = 'Uptime' group by `"+xAxis+"`) as t group by `"+xAxis+"` "+fixOrderString+"  ;alter table test add column `"+Constants.OTHERS+"' INTEGER ;");
            query.executeUpdate();
            query = session.createSQLQuery("update test,temp set `"+Constants.OTHERS+"` = temp.length where test.`"+xAxis+"` = temp.`"+xAxis+"`;");
            query.executeUpdate();
            query = session.createSQLQuery("select * from test "+fixOrderString+" ;");
4

1 に答える 1

0

その例外をキャッチし、それを出力して根本原因を確認します。たとえば、Log4j でこれを行うことができます。

log.error("Error", e);

根本的な原因は、最初のステートメントで作成された一時テーブルが、何らかの理由で次のステートメントで実際に表示されないことである可能性があります。

于 2012-12-10T22:53:45.947 に答える