我有条件,一个问题可以有多个答案,在查询中,我传递问题ID以检索答案。
public List<TbDiscussionForumAnswere> findTbDiscussionForumAnswerebyforumQuestionId(Integer forumQuestionId) {
session = sessionFactory.getCurrentSession();
System.out.println("Before"+forumQuestionId);
List<TbDiscussionForumAnswere> tbDiscussionForumAnswereList = session
.createCriteria(TbDiscussionForumAnswere.class)
.add(Restrictions.eq("forumQuestionId.forumQuestionId", forumQuestionId)).list();
System.out.println("AFTER "+forumQuestionId);
return TbDiscussionForumAnswereList;
}
实体如下
@JoinColumn(name = "ForumQuestionId", referencedColumnName = "ForumQuestionId")
@ManyToOne
private TbDiscussionForumQuestion forumQuestionId;
另一个就像
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "ForumQuestionId")
private Integer forumQuestionId;
以下查询我在尝试获取数据时从hibernate获取
select forumanswe0_.Answere_Id as Answere_2_91_0_, forumanswe0_.Id as Id1_41_0_, forumanswe0_.Id as Id1_41_1_, forumanswe0_.Answere_Id as Answere_2_41_1_, forumanswe0_.Case_Id as Case_Id3_41_1_, forumanswe0_.Resource_Id as Resource4_41_1_, case1x1_.Case_Id as Case_Id1_8_2_, case1x1_.Age as Age2_8_2_, case1x1_.Atelectasis as Atelecta3_8_2_, case1x1_.BaseLine_CA125 as BaseLine4_8_2_, case1x1_.Brca as Brca5_8_2_, case1x1_.Cancer_Sub_Type_Id as Cancer110_8_2_, case1x1_.Cancer_Type_Id as Cancer111_8_2_, case1x1_.Case_HER2neu_Amplified as Case_HER6_8_2_, case1x1_.Chief_Complaint as Chief_Co7_8_2_, case1x1_.Clinical_Stage as Clinical8_8_2_, case1x1_.Clinical_Staging_Method as Clinical9_8_2_, case1x1_.Closest_Margins as Closest10_8_2_, case1x1_.Date_First_Encounter as Date_Fi11_8_2_, case1x1_.Date_Recurrence as Date_Re12_8_2_, case1x1_.Debulking_Status as Debulki13_8_2_, case1x1_.Deceased_Due_BC as Decease14_8_2_, case1x1_.Disease_Propagation as Disease15_8_2_, case1x1_.disease_sub_type_id as diseas112_8_2_, case1x1_.Disease_Treated as Disease16_8_2_, case1x1_.Disease_type as Diseas113_8_2_, case1x1_.dist as dist17_8_2_, case1x1_.Distant_Mets as Distant18_8_2_, case1x1_.Distant_Mets_Comm as Distant19_8_2_, case1x1_.Dt_Death as Dt_Deat20_8_2_, case1x1_.Duration_Of_Symptoms_Mon as Duratio21_8_2_, case1x1_.ER_Percent as ER_Perc22_8_2_, case1x1_.ER_Status as ER_Stat23_8_2_, case1x1_.Esophageal_C_Staging_Method as Esophag24_8_2_, case1x1_.Esophagectomy_Done as Esophag25_8_2_, case1x1_.Final_TNM_Stage_Id as Final_114_8_2_, case1x1_.functional_status as functi115_8_2_, case1x1_.GYN_Oncologist as GYN_Onc26_8_2_, case1x1_.Genetics as Geneti116_8_2_, case1x1_.Genomics as Genomi117_8_2_, case1x1_.Gleason_Score as Gleason27_8_2_, case1x1_.HER2_Status as HER28_8_2_, case1x1_.HER2_SISH as HER29_8_2_, case1x1_.Histological_Grade as Histolo30_8_2_, case1x1_.ido as ido31_8_2_, case1x1_.Immune_Histochemistry as Immune_32_8_2_, case1x1_.Interval_Debulking_Dt as Interva33_8_2_, case1x1_.Invasion_In_Mediastnum as Invasio34_8_2_, case1x1_.Invasion_Into_Carina as Invasio35_8_2_, case1x1_.Invasion_Into_Esophagus as Invasio36_8_2_, case1x1_.Invasion_Into_Great_Vessels as Invasio37_8_2_, case1x1_.Invasion_Into_Heart as Invasio38_8_2_, case1x1_.Invasion_Into_Rec_Laryngeal_Nerve as Invasio39_8_2_, case1x1_.Invasion_Into_Trachea as Invasio40_8_2_, case1x1_.Invasion_Into_Vertbral_Body as Invasio41_8_2_, case1x1_.Invasion_Of_Adj_Structure as Invasio42_8_2_, case1x1_.Invasion_Of_Chest_Wall as Invasio43_8_2_, case1x1_.Invasion_Of_Diaphragm as Invasio44_8_2_, case1x1_.Invasion_Of_Main_Bronchus as Invasio45_8_2_, case1x1_.Invasion_Of_Pericardium as Invasio46_8_2_, case1x1_.Invasion_Of_Phrenic_Nerve as Invasio47_8_2_, case1x1_.Invasion_Of_Pleura as Invasio48_8_2_, case1x1_.Later as Later49_8_2_, case1x1_.lesion_depth as lesion_50_8_2_, case1x1_.Lymfovascular_Invasion as Lymfova51_8_2_, case1x1_.Margins as Margins52_8_2_, case1x1_.Med_Onc_Physician_Id as Med_On118_8_2_, case1x1_.Menopause_Status as Menopau53_8_2_, case1x1_.met_primary as met_pri54_8_2_, case1x1_.met_primary_site as met_pri55_8_2_, case1x1_.metastasis as metasta56_8_2_, case1x1_.Metastatic as Metasta57_8_2_, case1x1_.mi as mi58_8_2_, case1x1_.mucosal_invasion as mucosal59_8_2_, case1x1_.nd_Primary as nd_Prim60_8_2_, case1x1_.Necrosis_Percent as Necrosi61_8_2_, case1x1_.Necrosis_Present as Necrosi62_8_2_, case1x1_.NeoadjResponse as NeoadjR63_8_2_, case1x1_.nln as nln64_8_2_, case1x1_.No_Fossi as No_Foss65_8_2_, case1x1_.No_Nodes as No_Node66_8_2_, case1x1_.Nodal_Metastases as Nodal_M67_8_2_, case1x1_.nv_inf as nv_inf68_8_2_, case1x1_.nyso as nyso69_8_2_, case1x1_.Obstractive_Pneumonitis as Obstrac70_8_2_, case1x1_.OncDxScore as OncDxSc71_8_2_, case1x1_.other_biomarkers as other_b72_8_2_, case1x1_.Overall_Survival as Overall73_8_2_, case1x1_.PR_Percent as PR_Perc74_8_2_, case1x1_.PR_Status as PR_Stat75_8_2_, case1x1_.pathologist as patholo76_8_2_, case1x1_.Patient_Id as Patien119_8_2_, case1x1_.Plastic_Surgeon_Id as Plasti120_8_2_, case1x1_.Platin_Status as Platin_77_8_2_, case1x1_.pleural_Inv as pleural78_8_2_, case1x1_.Prg_Free_Survival as Prg_Fre79_8_2_, case1x1_.Primary_Diagnosis_Dt as Primary80_8_2_, case1x1_.Rad_Onc_Physician_Id as Rad_On121_8_2_, case1x1_.Reason_Not_Treated as Reason_81_8_2_, case1x1_.Recurrence as Recurre82_8_2_, case1x1_.ref_Physician as ref_Phy83_8_2_, case1x1_.Reference_Institution as Refere122_8_2_, case1x1_.Refering_Physicia_Id as Referi123_8_2_, case1x1_.Residual_Tumor as Residua84_8_2_, case1x1_.Secondary_Debulking_Date as Seconda85_8_2_, case1x1_.Seen_On_Bonescan as Seen_On86_8_2_, case1x1_.Seen_On_CT as Seen_On87_8_2_, case1x1_.Seen_On_MRI as Seen_On88_8_2_, case1x1_.Seen_On_PAT as Seen_On89_8_2_, case1x1_.Seen_On_Thallium_Scan as Seen_On90_8_2_, case1x1_.Seen_On_Xray as Seen_On91_8_2_, case1x1_.Separate_TNode_In_Same_Lobe as Separat92_8_2_, case1x1_.Significance_Comorbities as Signifi93_8_2_, case1x1_.Significance_Risk as Signifi94_8_2_, case1x1_.st_Primary as st_Prim95_8_2_, case1x1_.Surg_Onc_Physician_Id as Surg_O124_8_2_, case1x1_.t_location as t_locat96_8_2_, case1x1_.TNodes_In_Diff_Lobe as TNodes_97_8_2_, case1x1_.t_rupture as t_ruptu98_8_2_, case1x1_.tis_bank as tis_ban99_8_2_, case1x1_.tis_bank_odunsi as tis_ba100_8_2_, case1x1_.tis_bank_pnr as tis_ba101_8_2_, case1x1_.Treatment_Related_Death as Treatm102_8_2_, case1x1_.Tumor_Depth as Tumor_103_8_2_, case1x1_.Tumor_Size as Tumor_104_8_2_, case1x1_.tumor_type as tumor_105_8_2_, case1x1_.Unrelated_Death as Unrela106_8_2_, case1x1_.version as versio107_8_2_, case1x1_.WHO_Classification as WHO_Cl108_8_2_, case1x1_.Working_TNM_Stage_Id as Workin125_8_2_, case1x1_.wt as wt109_8_2_, cancersubt2_.Can_Sub_Type_Id as Can_Sub_1_5_3_, cancersubt2_.Cancer_Type_Id as Cancer_T3_5_3_, cancersubt2_.Name as Name2_5_3_, cancertype3_.Can_Type_Id as Can_Type1_6_4_, cancertype3_.CName as CName2_6_4_, cancertype3_.Comments as Comments3_6_4_, cancertype3_.disease_sub_type_id as disease_4_6_4_, cancertype3_.disease_type_Id as disease_5_6_4_, diseasesub4_.Disease_Sub_Type_Id as Disease_1_24_5_, diseasesub4_.Creation_Time as Creation2_24_5_, diseasesub4_.Disease_Sub_Name as Disease_3_24_5_, diseasesub4_.Disease_Type_Id as Disease_5_24_5_, diseasesub4_.Modifcation_Time as Modifcat4_24_5_, diseasetyp5_.Disease_Type_Id as Disease_1_25_6_, diseasetyp5_.Disease_Name as Disease_2_25_6_, diseasetyp6_.Disease_Type_Id as Disease_1_25_7_, diseasetyp6_.Disease_Name as Disease_2_25_7_, cancertype7_.Can_Type_Id as Can_Type1_6_8_, cancertype7_.CName as CName2_6_8_, cancertype7_.Comments as Comments3_6_8_, cancertype7_.disease_sub_type_id as disease_4_6_8_, cancertype7_.disease_type_Id as disease_5_6_8_, diseasesub8_.Disease_Sub_Type_Id as Disease_1_24_9_, diseasesub8_.Creation_Time as Creation2_24_9_, diseasesub8_.Disease_Sub_Name as Disease_3_24_9_, diseasesub8_.Disease_Type_Id as Disease_5_24_9_, diseasesub8_.Modifcation_Time as Modifcat4_24_9_, diseasetyp9_.Disease_Type_Id as Disease_1_25_10_, diseasetyp9_.Disease_Name as Disease_2_25_10_, tnmstage10_.Stage_Id as Stage_Id1_95_11_, tnmstage10_.Value as Value2_95_11_, functional11_.Id as Id1_43_12_, functional11_.Status as Status2_43_12_, genetics12_.Id as Id1_45_13_, genetics12_.GnName as GnName2_45_13_, gemonics13_.Id as Id1_44_14_, gemonics13_.GName as GName2_44_14_, physician14_.Physician_Id as Physicia1_59_15_, physician14_.Cancer_Type_Id as Cancer_T9_59_15_, physician14_.Disease_Type_Id as Disease10_59_15_, physician14_.EMailId as EMailId2_59_15_, physician14_.Facility_Id as Facilit11_59_15_, physician14_.FNAME as FNAME3_59_15_, physician14_.LNAME as LNAME4_59_15_, physician14_.MINIT as MINIT5_59_15_, physician14_.PhoneNo as PhoneNo6_59_15_, physician14_.Phy_Group as Phy_Grou7_59_15_, physician14_.Profile_Image as Profile_8_59_15_, physician14_.Specialty as Special12_59_15_, cancertype15_.Can_Type_Id as Can_Type1_6_16_, cancertype15_.CName as CName2_6_16_, cancertype15_.Comments as Comments3_6_16_, cancertype15_.disease_sub_type_id as disease_4_6_16_, cancertype15_.disease_type_Id as disease_5_6_16_, diseasetyp16_.Disease_Type_Id as Disease_1_25_17_, diseasetyp16_.Disease_Name as Disease_2_25_17_, carefacili17_.Facility_Id as Facility1_7_18_, carefacili17_.Center_Type_Id as Center_T7_7_18_, carefacili17_.Facility_Address as Facility2_7_18_, carefacili17_.Facility_City as Facility3_7_18_, carefacili17_.Facility_Name as Facility4_7_18_, carefacili17_.Facility_State as Facility5_7_18_, carefacili17_.Facility_Type_Type as Facility8_7_18_, carefacili17_.Facility_Zip as Facility6_7_18_, carefacili17_.NQMBC_Certiification_Level_Id as NQMBC_Ce9_7_18_, breastcanc18_.Center_type_Id as Center_t1_2_19_, breastcanc18_.Center_Type_Description as Center_T2_2_19_, facilityty19_.Type_Id as Type_Id1_38_20_, facilityty19_.FName as FName2_38_20_, nqmbclevel20_.Level_Id as Level_Id1_51_21_, nqmbclevel20_.LName as LName2_51_21_, physicians21_.Type_Id as Type_Id1_60_22_, physicians21_.Name as Name2_60_22_, patient22_.Patient_Id as Patient_1_55_23_, patient22_.Active as Active2_55_23_, patient22_.Address as Address3_55_23_, patient22_.Birth_Date as Birth_Da4_55_23_, patient22_.Cell_Phone_Number as Cell_Pho5_55_23_, patient22_.City as City6_55_23_, patient22_.Emergency_Contact_Name as Emergenc7_55_23_, patient22_.Emergency_Contact_Phone_Number as Emergenc8_55_23_, patient22_.Employement_Type as Employem9_55_23_, patient22_.Ethnicity as Ethnici10_55_23_, patient22_.FName as FName11_55_23_, patient22_.Functional_Status as Functio24_55_23_, patient22_.Gender as Gender12_55_23_, patient22_.Increase_Risk as Increas13_55_23_, patient22_.Insurance_Name as Insuran14_55_23_, patient22_.LName as LName15_55_23_, patient22_.MName as MName16_55_23_, patient22_.Mammographic_Breast_Density as Mammogr17_55_23_, patient22_.MedRecNo as MedRecN18_55_23_, patient22_.Patient_Concerns as Patient19_55_23_, patient22_.Phone_Number as Phone_N20_55_23_, patient22_.Race as Race25_55_23_, patient22_.Status as Status21_55_23_, patient22_.Work_Phone_Number as Work_Ph22_55_23_, patient22_.zipcode as zipcode23_55_23_, functional23_.Id as Id1_43_24_, functional23_.Status as Status2_43_24_, race24_.Type_Id as Type_Id1_68_25_, race24_.Race as Race2_68_25_, physician25_.Physician_Id as Physicia1_59_26_, physician25_.Cancer_Type_Id as Cancer_T9_59_26_, physician25_.Disease_Type_Id as Disease10_59_26_, physician25_.EMailId as EMailId2_59_26_, physician25_.Facility_Id as Facilit11_59_26_, physician25_.FNAME as FNAME3_59_26_, physician25_.LNAME as LNAME4_59_26_, physician25_.MINIT as MINIT5_59_26_, physician25_.PhoneNo as PhoneNo6_59_26_, physician25_.Phy_Group as Phy_Grou7_59_26_, physician25_.Profile_Image as Profile_8_59_26_, physician25_.Specialty as Special12_59_26_, physician26_.Physician_Id as Physicia1_59_27_, physician26_.Cancer_Type_Id as Cancer_T9_59_27_, physician26_.Disease_Type_Id as Disease10_59_27_, physician26_.EMailId as EMailId2_59_27_, physician26_.Facility_Id as Facilit11_59_27_, physician26_.FNAME as FNAME3_59_27_, physician26_.LNAME as LNAME4_59_27_, physician26_.MINIT as MINIT5_59_27_, physician26_.PhoneNo as PhoneNo6_59_27_, physician26_.Phy_Group as Phy_Grou7_59_27_, physician26_.Profile_Image as Profile_8_59_27_, physician26_.Specialty as Special12_59_27_, carefacili27_.Facility_Id as Facility1_7_28_, carefacili27_.Center_Type_Id as Center_T7_7_28_, carefacili27_.Facility_Address as Facility2_7_28_, carefacili27_.Facility_City as Facility3_7_28_, carefacili27_.Facility_Name as Facility4_7_28_, carefacili27_.Facility_State as Facility5_7_28_, carefacili27_.Facility_Type_Type as Facility8_7_28_, carefacili27_.Facility_Zip as Facility6_7_28_, carefacili27_.NQMBC_Certiification_Level_Id as NQMBC_Ce9_7_28_, physician28_.Physician_Id as Physicia1_59_29_, physician28_.Cancer_Type_Id as Cancer_T9_59_29_, physician28_.Disease_Type_Id as Disease10_59_29_, physician28_.EMailId as EMailId2_59_29_, physician28_.Facility_Id as Facilit11_59_29_, physician28_.FNAME as FNAME3_59_29_, physician28_.LNAME as LNAME4_59_29_, physician28_.MINIT as MINIT5_59_29_, physician28_.PhoneNo as PhoneNo6_59_29_, physician28_.Phy_Group as Phy_Grou7_59_29_, physician28_.Profile_Image as Profile_8_59_29_, physician28_.Specialty as Special12_59_29_, physician29_.Physician_Id as Physicia1_59_30_, physician29_.Cancer_Type_Id as Cancer_T9_59_30_, physician29_.Disease_Type_Id as Disease10_59_30_, physician29_.EMailId as EMailId2_59_30_, physician29_.Facility_Id as Facilit11_59_30_, physician29_.FNAME as FNAME3_59_30_, physician29_.LNAME as LNAME4_59_30_, physician29_.MINIT as MINIT5_59_30_, physician29_.PhoneNo as PhoneNo6_59_30_, physician29_.Phy_Group as Phy_Grou7_59_30_, physician29_.Profile_Image as Profile_8_59_30_, physician29_.Specialty as Special12_59_30_, tnmstage30_.Stage_Id as Stage_Id1_95_31_, tnmstage30_.Value as Value2_95_31_, medikmreso31_.Resourse_Id as Resourse1_49_32_, medikmreso31_.answer_id as answer_i2_49_32_, medikmreso31_.Date_Of_Posted as Date_Of_3_49_32_, medikmreso31_.Description as Descript4_49_32_, medikmreso31_.DiseaseType as Disease14_49_32_, medikmreso31_.Evidence_Level as Evidence5_49_32_, medikmreso31_.External_Url as External6_49_32_, medikmreso31_.File_Name as File_Nam7_49_32_, medikmreso31_.Keywords as Keywords8_49_32_, medikmreso31_.Name as Name9_49_32_, medikmreso31_.Provider_ID as Provide15_49_32_, medikmreso31_.Publication_Year as Publica10_49_32_, medikmreso31_.Source as Source11_49_32_, medikmreso31_.Type as Type12_49_32_, medikmreso31_.Visibility as Visibil13_49_32_, diseasetyp32_.Disease_Type_Id as Disease_1_25_33_, diseasetyp32_.Disease_Name as Disease_2_25_33_, physician33_.Physician_Id as Physicia1_59_34_, physician33_.Cancer_Type_Id as Cancer_T9_59_34_, physician33_.Disease_Type_Id as Disease10_59_34_, physician33_.EMailId as EMailId2_59_34_, physician33_.Facility_Id as Facilit11_59_34_, physician33_.FNAME as FNAME3_59_34_, physician33_.LNAME as LNAME4_59_34_, physician33_.MINIT as MINIT5_59_34_, physician33_.PhoneNo as PhoneNo6_59_34_, physician33_.Phy_Group as Phy_Grou7_59_34_, physician33_.Profile_Image as Profile_8_59_34_, physician33_.Specialty as Special12_59_34_ from forum_answere_resources forumanswe0_ inner join case1 case1x1_ on forumanswe0_.Case_Id=case1x1_.Case_Id left outer join cancer_sub_type cancersubt2_ on case1x1_.Cancer_Sub_Type_Id=cancersubt2_.Can_Sub_Type_Id left outer join cancer_type cancertype3_ on cancersubt2_.Cancer_Type_Id=cancertype3_.Can_Type_Id left outer join disease_sub_type diseasesub4_ on cancertype3_.disease_sub_type_id=diseasesub4_.Disease_Sub_Type_Id left outer join disease_type diseasetyp5_ on diseasesub4_.Disease_Type_Id=diseasetyp5_.Disease_Type_Id left outer join disease_type diseasetyp6_ on cancertype3_.disease_type_Id=diseasetyp6_.Disease_Type_Id left outer join cancer_type cancertype7_ on case1x1_.Cancer_Type_Id=cancertype7_.Can_Type_Id left outer join disease_sub_type diseasesub8_ on case1x1_.disease_sub_type_id=diseasesub8_.Disease_Sub_Type_Id inner join disease_type diseasetyp9_ on case1x1_.Disease_type=diseasetyp9_.Disease_Type_Id left outer join tnm_stage tnmstage10_ on case1x1_.Final_TNM_Stage_Id=tnmstage10_.Stage_Id left outer join functionalstatus functional11_ on case1x1_.functional_status=functional11_.Id left outer join genetics genetics12_ on case1x1_.Genetics=genetics12_.Id left outer join gemonics gemonics13_ on case1x1_.Genomics=gemonics13_.Id left outer join physician physician14_ on case1x1_.Med_Onc_Physician_Id=physician14_.Physician_Id left outer join cancer_type cancertype15_ on physician14_.Cancer_Type_Id=cancertype15_.Can_Type_Id left outer join disease_type diseasetyp16_ on physician14_.Disease_Type_Id=diseasetyp16_.Disease_Type_Id left outer join care_facility carefacili17_ on physician14_.Facility_Id=carefacili17_.Facility_Id left outer join breast_cancer_center_type breastcanc18_ on carefacili17_.Center_Type_Id=breastcanc18_.Center_type_Id left outer join facility_type facilityty19_ on carefacili17_.Facility_Type_Type=facilityty19_.Type_Id left outer join nqmbc_level nqmbclevel20_ on carefacili17_.NQMBC_Certiification_Level_Id=nqmbclevel20_.Level_Id left outer join physician_speciality physicians21_ on physician14_.Specialty=physicians21_.Type_Id inner join patient patient22_ on case1x1_.Patient_Id=patient22_.Patient_Id left outer join functionalstatus functional23_ on patient22_.Functional_Status=functional23_.Id left outer join race race24_ on patient22_.Race=race24_.Type_Id left outer join physician physician25_ on case1x1_.Plastic_Surgeon_Id=physician25_.Physician_Id left outer join physician physician26_ on case1x1_.Rad_Onc_Physician_Id=physician26_.Physician_Id left outer join care_facility carefacili27_ on case1x1_.Reference_Institution=carefacili27_.Facility_Id left outer join physician physician28_ on case1x1_.Refering_Physicia_Id=physician28_.Physician_Id left outer join physician physician29_ on case1x1_.Surg_Onc_Physician_Id=physician29_.Physician_Id left outer join tnm_stage tnmstage30_ on case1x1_.Working_TNM_Stage_Id=tnmstage30_.Stage_Id inner join medikm_resources medikmreso31_ on forumanswe0_.Resource_Id=medikmreso31_.Resourse_Id inner join disease_type diseasetyp32_ on medikmreso31_.DiseaseType=diseasetyp32_.Disease_Type_Id left outer join physician physician33_ on medikmreso31_.Provider_ID=physician33_.Physician_Id where forumanswe0_.Answere_Id=?
答案 0 :(得分:0)
您需要查看实体的获取策略,特别是具有ManyToOne关系的那些(检查this post),默认为EAGER获取类型或以编程方式指定获取类型,例如:
List<TbDiscussionForumAnswere> tbDiscussionForumAnswereList = session.createCriteria(TbDiscussionForumAnswere.class)
.add(Restrictions.eq("forumQuestionId.forumQuestionId",forumQuestionId))
.setFetchMode("forumQuestionId", FetchMode.LAZY)
.list();