0

私は Web ポータルを構築しており、Hibernate を使用して MySQL にアクセスし、フェッチしたデータを JSP にプッシュして表形式で印刷しています。サーブレットの展開に Tomcat を使用しています。私のサーブレットは 3 つの HQL クエリを作成し、取得したデータを JSP にプッシュする必要があります。サーブレットを展開した後、HTML フォームを使用して初めてクエリを作成したときに正常に動作します。さらに、Eclipse コンソールでは、実行中の 3 つの HQL クエリがすべて表示されます。しかし、もう一度クエリを作成しようとすると、HTML フォームから前回と同じクエリを実行しても、JSP ページにデータが表示されません (入力しようとしていたテーブルにはゼロしか含まれていません)。Eclipse コンソールをチェックすると、最初の HQL クエリのみが実行され、エラー メッセージさえも何も表示されないことがわかりました。Tomcatを再起動するか、サーブレットを再デプロイすると機能しますが、もう一度だけです。助けてください

HTMLフォーム→サーブレット→JSPの流れです。

         String major,date,minor,ip;
         double[][][] transactionTime = new double[2][50][10];
         int[] testCaseId = new int[10];
         String[] activityName = new String[10];
         major=req.getParameter("major");
         date=req.getParameter("date");
         minor=req.getParameter("minor");
         ip=req.getParameter("ip");
         String testCaseName=req.getParameter("testCaseName");
         Session session = null;


      try{

      SessionFactory sessionFactory = new 

    Configuration().configure()
    .buildSessionFactory();
      session =sessionFactory.openSession();

      //Create Select Clause HQL


         String SQL_QUERY2 ="Select testCases.activityName,testCases.testCaseID from TestCases testCases where testCases.testcaseName like \'" + testCaseName + "\'";
         Query query2 = session.createQuery(SQL_QUERY2);
         for(Iterator it2=query2.iterate();it2.hasNext();ctr2++)
              {
              Object[] act = (Object[]) it2.next();
              activityName[ctr2]=(String) act[0];
              testCaseId[ctr2] = (Integer) act[1];
              }


        for(int j=0;j<ctr2;j++){
            ctr=0;
         String SQL_QUERY3 ="Select tran.transactionTime from Transactions tran where tran.samples.builds.buildMajorVersion like " + major + " and tran.samples.builds.buildMinorVersion like " + minor + " and tran.samples.runDate like \'" + date + "\' and tran.testCases.testCaseID like " + testCaseId[j] + " and tran.samples.testbeds.server.ipv4Address like \'" + ip + "\'";
         Query query3 = session.createQuery(SQL_QUERY3);
         for(Iterator it3=query3.iterate();it3.hasNext();ctr++)
              {
              Object time = (Object) it3.next();
              transactionTime[0][j][ctr]=(Double) time;
              int precision = 100;
              transactionTime[0][j][ctr] = Math.floor(transactionTime[0][j][ctr]*precision+0.5)/precision;
              }
        }



        for(int j=0;j<ctr2;j++){
            ctr3=0;
         String SQL_QUERY5 ="Select tran.transactionTime from Transactions tran where tran.samples.builds.buildMajorVersion like " + major + " and tran.samples.builds.buildMinorVersion like " + minor + " and tran.samples.baseline=1";
         Query query5 = session.createQuery(SQL_QUERY5);
         for(Iterator it5=query5.iterate();it5.hasNext();ctr3++)
              {
              Object time = (Object) it5.next();
              transactionTime[1][j][ctr3]=(Double) time;
              int precision = 100;
              transactionTime[1][j][ctr3] = Math.floor(transactionTime[1][j][ctr3]*precision+0.5)/precision;
              }
        }





 session.close();
      }
      catch(Exception e){
          System.out.println(e.getMessage());
      }
      finally{

      }







    req.setAttribute("major",major);
    req.setAttribute("minor",minor);
    req.setAttribute("date",date);
    req.setAttribute("ip",ip);
    req.setAttribute("testCaseName",testCaseName);
    req.setAttribute("transactionTime", transactionTime);
    req.setAttribute("activityName", activityName);
    req.setAttribute("sampleNumBase", ctr3);
    req.setAttribute("sampleNumRun", ctr);
      req.getRequestDispatcher("/WEB-INF/src/BaselineRawData.jsp").forward(req, res);  
 }

}

最初の正常な実行時の Eclipse のコンソール出力

Hibernate: 
    select
        testcases0_.activityName as col_0_0_,
        testcases0_.testCaseID as col_1_0_ 
    from
        TestCases testcases0_ 
    where
        testcases0_.testcaseName like 'Deploy 200 tunings on 10 devices with 0 tunings' Hibernate: 
    select
        transactio0_.transactionTime as col_0_0_ 
    from
        Transactions transactio0_ cross 
    join
        Samples samples1_ cross 
    join
        Builds builds2_ cross 
    join
        TestBeds testbeds7_ cross 
    join
        Machines server8_ 
    where
        transactio0_.sampleId=samples1_.sampleId 
        and samples1_.buildId=builds2_.buildId 
        and samples1_.testBedId=testbeds7_.testBedId 
        and testbeds7_.serverId=server8_.machineId 
        and (
            builds2_.buildMajorVersion like 4
        ) 
        and (
            builds2_.buildMinorVersion like 4434
        ) 
        and (
            samples1_.runDate like '2012-02-25'
        ) 
        and (
            transactio0_.testCaseId like 1
        ) 
        and (
            server8_.ipv4Address like '10.104.52.200'
        ) Hibernate: 
    select
        transactio0_.transactionTime as col_0_0_ 
    from
        Transactions transactio0_ cross 
    join
        Samples samples1_ cross 
    join
        Builds builds2_ cross 
    join
        TestBeds testbeds7_ cross 
    join
        Machines server8_ 
    where
        transactio0_.sampleId=samples1_.sampleId 
        and samples1_.buildId=builds2_.buildId 
        and samples1_.testBedId=testbeds7_.testBedId 
        and testbeds7_.serverId=server8_.machineId 
        and (
            builds2_.buildMajorVersion like 4
        ) 
        and (
            builds2_.buildMinorVersion like 4434
        ) 
        and (
            samples1_.runDate like '2012-02-25'
        ) 
        and (
            transactio0_.testCaseId like 2
        ) 
        and (
            server8_.ipv4Address like '10.104.52.200'
        ) Hibernate: 
    select
        transactio0_.transactionTime as col_0_0_ 
    from
        Transactions transactio0_ cross 
    join
        Samples samples1_ cross 
    join
        Builds builds2_ cross 
    join
        TestBeds testbeds7_ cross 
    join
        Machines server8_ 
    where
        transactio0_.sampleId=samples1_.sampleId 
        and samples1_.buildId=builds2_.buildId 
        and samples1_.testBedId=testbeds7_.testBedId 
        and testbeds7_.serverId=server8_.machineId 
        and (
            builds2_.buildMajorVersion like 4
        ) 
        and (
            builds2_.buildMinorVersion like 4434
        ) 
        and (
            samples1_.runDate like '2012-02-25'
        ) 
        and (
            transactio0_.testCaseId like 3
        ) 
        and (
            server8_.ipv4Address like '10.104.52.200'
        ) Hibernate: 
    select
        transactio0_.transactionTime as col_0_0_ 
    from
        Transactions transactio0_ cross 
    join
        Samples samples1_ cross 
    join
        Builds builds2_ cross 
    join
        TestBeds testbeds7_ cross 
    join
        Machines server8_ 
    where
        transactio0_.sampleId=samples1_.sampleId 
        and samples1_.buildId=builds2_.buildId 
        and samples1_.testBedId=testbeds7_.testBedId 
        and testbeds7_.serverId=server8_.machineId 
        and (
            builds2_.buildMajorVersion like 4
        ) 
        and (
            builds2_.buildMinorVersion like 4434
        ) 
        and (
            samples1_.runDate like '2012-02-25'
        ) 
        and (
            transactio0_.testCaseId like 4
        ) 
        and (
            server8_.ipv4Address like '10.104.52.200'
        ) Hibernate: 
    select
        transactio0_.transactionTime as col_0_0_ 
    from
        Transactions transactio0_ cross 
    join
        Samples samples1_ cross 
    join
        Builds builds2_ cross 
    join
        TestBeds testbeds7_ cross 
    join
        Machines server8_ 
    where
        transactio0_.sampleId=samples1_.sampleId 
        and samples1_.buildId=builds2_.buildId 
        and samples1_.testBedId=testbeds7_.testBedId 
        and testbeds7_.serverId=server8_.machineId 
        and (
            builds2_.buildMajorVersion like 4
        ) 
        and (
            builds2_.buildMinorVersion like 4434
        ) 
        and (
            samples1_.runDate like '2012-02-25'
        ) 
        and (
            transactio0_.testCaseId like 5
        ) 
        and (
            server8_.ipv4Address like '10.104.52.200'
        ) Hibernate: 
    select
        transactio0_.transactionTime as col_0_0_ 
    from
        Transactions transactio0_ cross 
    join
        Samples samples1_ cross 
    join
        Builds builds2_ cross 
    join
        TestBeds testbeds7_ cross 
    join
        Machines server8_ 
    where
        transactio0_.sampleId=samples1_.sampleId 
        and samples1_.buildId=builds2_.buildId 
        and samples1_.testBedId=testbeds7_.testBedId 
        and testbeds7_.serverId=server8_.machineId 
        and (
            builds2_.buildMajorVersion like 4
        ) 
        and (
            builds2_.buildMinorVersion like 4434
        ) 
        and (
            samples1_.runDate like '2012-02-25'
        ) 
        and (
            transactio0_.testCaseId like 6
        ) 
        and (
            server8_.ipv4Address like '10.104.52.200'
        ) Hibernate: 
    select
        transactio0_.transactionTime as col_0_0_ 
    from
        Transactions transactio0_ cross 
    join
        Samples samples1_ cross 
    join
        Builds builds2_ 
    where
        transactio0_.sampleId=samples1_.sampleId 
        and samples1_.buildId=builds2_.buildId 
        and (
            builds2_.buildMajorVersion like 4
        ) 
        and (
            builds2_.buildMinorVersion like 4434
        ) 
        and samples1_.baseline=1 10

後続の実行および失敗した実行に関する Eclipse のコンソール出力

Hibernate: 
    select
        testcases0_.activityName as col_0_0_,
        testcases0_.testCaseID as col_1_0_ 
    from
        TestCases testcases0_ 
    where
        testcases0_.testcaseName like 'Deploy 200 tunings on 10 devices with 0 tunings'
10
4

1 に答える 1

0

ハーディク氏は、問題ctr2は ループの反復はそれに基づいているためです。どこで初期化されますか?

問題は、ctr2およびctrが d サーブレット コードの外部で宣言および初期化されたことです。

于 2012-04-18T09:04:29.450 に答える