2

同封のコードを実行すると、それ以上の説明がない SQLGrammarException が返されます。このコードを mysql データベースに対して実行しています。誰かがこのクエリの何が問題なのか理解できますか?

    public PatientId getPatientByAccount(String account_) {
    Session session = null;
    PatientId patient = null;
    try {

        session = HibernateUtils.beginTransaction("emscribedx");
        session.beginTransaction();
        String queryString = "from PatientId where acct = :acct";
        Query query = session.createQuery(queryString);
        query.setString("acct", account_);
        Object queryResult = query.uniqueResult();
        patient = (PatientId)queryResult;
        session.getTransaction().commit();

    } catch (HibernateException e_) {
        System.out.println("Problem getting patientId for acct=" + account_
                + " " + e_.toString());
        NTEVENT_LOG.error("Problem getting patientId for acct=" + account_
                + " " + e_.getStackTrace());
    } finally {
        if (session != null && session.isOpen()) {
            try {
                HibernateUtils.closeSessions();
            } catch (HibernateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    return patient;

}

それが役立つ場合、クエリは次の sql を生成しています。

    select
    patientid0_.pid as pid7_,
    patientid0_.aprdrg as aprdrg7_,
    patientid0_.fid as fid7_,
    patientid0_.acct as acct7_,
    patientid0_.create_date as create5_7_,
    patientid0_.mr as mr7_,
    patientid0_.sex as sex7_,
    patientid0_.race as race7_,
    patientid0_.age as age7_,
    patientid0_.AdmitDate as AdmitDate7_,
    patientid0_.admittime as admittime7_,
    patientid0_.DischargeDate as Dischar12_7_,
    patientid0_.held as held7_,
    patientid0_.drgweight as drgweight7_,
    patientid0_.drgtext as drgtext7_,
    patientid0_.encodersystem as encoder16_7_,
    patientid0_.mdc as mdc7_,
    patientid0_.illnessSeverity as illness18_7_,
    patientid0_.mortalityRisk as mortali19_7_,
    patientid0_.eminfo as eminfo7_,
    patientid0_.emtime as emtime7_,
    patientid0_.Dischargetime as Dischar22_7_,
    patientid0_.Birthdate as Birthdate7_,
    patientid0_.transferfrom as transfe24_7_,
    patientid0_.DischargeDisp as Dischar25_7_,
    patientid0_.transferto as transferto7_,
    patientid0_.patientType as patient27_7_,
    patientid0_.admitReason as admitRe28_7_,
    patientid0_.DischargeNum as Dischar29_7_,
    patientid0_.admitSource as admitSo30_7_,
    patientid0_.admitType as admitType7_,
    patientid0_.prevstatus as prevstatus7_,
    patientid0_.patientLast as patient33_7_,
    patientid0_.patientFirst as patient34_7_,
    patientid0_.patientMiddle as patient35_7_,
    patientid0_.drg as drg7_,
    patientid0_.assignTo as assignTo7_,
    patientid0_.groupid as groupid7_,
    patientid0_.newDocs as newDocs7_,
    patientid0_.assignOrder as assignO40_7_,
    patientid0_.serviceType as service41_7_,
    patientid0_.dischargeDispFlag as dischar42_7_,
    patientid0_.PendingInfo1 as Pending43_7_,
    patientid0_.MaritalStatus as Marital44_7_,
    patientid0_.FinancialClass as Financi45_7_,
    patientid0_.MedicalService as Medical46_7_,
    patientid0_.assign_date as assign47_7_,
    patientid0_.assignby as assignby7_,
    patientid0_.ADTID as ADTID7_,
    patientid0_.notes as notes7_,
    patientid0_.CycleBeginDate as CycleBe51_7_,
    patientid0_.CycleEndDate as CycleEn52_7_,
    patientid0_.grouper as grouper7_,
    patientid0_.EstReimbursement as EstReim54_7_,
    patientid0_.initialdrg as initialdrg7_,
    patientid0_.product as product7_,
    patientid0_.billtype as billtype7_,
    patientid0_.PendingInfo2 as Pending58_7_,
    patientid0_.pendinginfo as pending59_7_,
    patientid0_.location as location7_,
    patientid0_.status as status7_ 
from
    emscribedx.patientid patientid0_ 
where
    patientid0_.acct=?
4

1 に答える 1

2

データベースが変更されたため、hibernate によって使用された基になるモデルにデータベースにない列が含まれていたことが判明しました。これにより、hibernate が sqlgrammarException をスローしました。残念ながら、Hibernate の例外は、データベースへの直接の jdbc 呼び出しで発生するものほど有益ではありません。

于 2013-01-26T04:39:34.520 に答える