gpt4 book ai didi

java - Hibernate HQL 查询导致 SQLGrammarException

转载 作者:行者123 更新时间:2023-11-29 02:30:08 25 4
gpt4 key购买 nike

当执行附带的代码时,我收到了一个 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=?

最佳答案

事实证明,数据库已被更改,因此 hibernate 使用的底层模型具有不在数据库中的列。这导致 hibernate 抛出 sqlgrammarException。不幸的是,Hibernate 异常并不像直接对数据库进行 jdbc 调用时所发生的那样提供信息。

关于java - Hibernate HQL 查询导致 SQLGrammarException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14532625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com