Here is something else I tried. Hibernate create the right SQL, but still gives me error. Code is
Code:
String sql = "";
sql += "SELECT ";
sql += "{gt.*} ";
sql += "FROM GS_TEAM gt ";
sql += "inner join TEAM_DETAIL td ON td.team_id = gt.team_id AND td.DRAFT_GS_TEAM_ID = gt.gs_team_id ";
sql += "inner join TEAM t ON t.team_id = td.team_id ";
sql += "inner join STORE s ON s.store_id = t.store_id ";
sql += "WHERE ";
sql += "(s.store_id = " + storeId + " OR s.parent_store_id = " + storeId+ ") AND ";
sql += "td.fiscal_period_id = " + fp.getFiscalPeriodId();
SQLQuery storeQuery = session.createSQLQuery(sql);
storeQuery.addEntity("gt", GsTeam.class);
storeQuery.addEntity("td", TeamDetail.class);
storeQuery.addEntity("t", Team.class);
storeQuery.addEntity("s", Store.class);
List storeList = storeQuery.list();
The generated SQL is below and executes successfully
Code:
SELECT gt.GS_TEAM_ID as GS1_0_, gt.GS_RUN_ID as GS2_35_0_, gt.TEAM_ID as TEAM3_35_0_, gt.INPUT_TEAM_SAVINGS_POOL as INPUT4_35_0_, gt.INPUT_DEEP_DEFICIT_FLAG as INPUT5_35_0_, gt.INPUT_OT_ADJ_FACTOR as INPUT6_35_0_, gt.INPUT_FP_OT_ADJ as INPUT7_35_0_, gt.INPUT_YR_OT_ADJ as INPUT8_35_0_, gt.INPUT_ALLOCATED_LABOR_PCT as INPUT9_35_0_, gt.INPUT_STORE_TEAM_PCT as INPUT10_35_0_, gt.INPUT_STORE_SAVINGS_POOL as INPUT11_35_0_, gt.INPUT_CONTRACT_LABOR as INPUT12_35_0_, gt.INPUT_VENDOR_CREDIT as INPUT13_35_0_, gt.INPUT_SUPPLEMENTAL_LABOR as INPUT14_35_0_, gt.CALC_OT_ADJ_TOTAL as CALC15_35_0_, gt.CALC_ADJ_SAVINGS_POOL as CALC16_35_0_, gt.CALC_TEAM_SALES as CALC17_35_0_, gt.CALC_ALLOCATED_LABOR_BUDGET as CALC18_35_0_, gt.CALC_ACTL_LABOR_COST_PP1 as CALC19_35_0_, gt.CALC_ACTL_LABOR_COST_PP2 as CALC20_35_0_, gt.CALC_ACTL_LABOR_COST_TOTAL as CALC21_35_0_, gt.CALC_LABOR_SURPLUS as CALC22_35_0_, gt.CALC_REG_LABOR_HOURS_PP1 as CALC23_35_0_, gt.CALC_REG_LABOR_HOURS_PP2 as CALC24_35_0_, gt.CALC_REG_LABOR_HOURS_TOTAL as CALC25_35_0_, gt.CALC_OT_LABOR_HOURS_PP1 as CALC26_35_0_, gt.CALC_OT_LABOR_HOURS_PP2 as CALC27_35_0_, gt.CALC_OT_LABOR_HOURS_TOTAL as CALC28_35_0_, gt.CALC_SURPLUS_TO_TEAM_PRELIM as CALC29_35_0_, gt.CALC_SURPLUS_TO_POOL_PRELIM as CALC30_35_0_, gt.CALC_SURPLUS_PER_REG_HOUR as CALC31_35_0_, gt.CALC_NEW_MEMBERS_ADJ as CALC32_35_0_, gt.CALC_TERMINATED_MEMBERS_ADJ as CALC33_35_0_, gt.CALC_ROUNDING_ADJ as CALC34_35_0_, gt.CALC_SURPLUS_TO_TEAM_FINAL as CALC35_35_0_, gt.OUTPUT_FP_SURPLUS_2_STORE_POOL as OUTPUT36_35_0_, gt.OUTPUT_FP_SURPLUS_TO_TEAM_POOL as OUTPUT37_35_0_, gt.OUTPUT_OT_ADJ as OUTPUT38_35_0_, gt.INPUT_NEEDS_OT_ADJ_FLAG as INPUT39_35_0_, gt.CALC_LABOR_SURPLUS_B4STORE as CALC40_35_0_, gt.MODIFIED_BY as MODIFIED41_35_0_, gt.MODIFIED_DT as MODIFIED42_35_0_, gt.CREATED_DT as CREATED43_35_0_, gt.CREATED_BY as CREATED44_35_0_, gt.INPUT_FRONT_END_FLAG as INPUT45_35_0_, gt.INPUT_ADMIN_FLAG as INPUT46_35_0_, gt.INPUT_SURPLUS_PER_HR_OVERRIDE as INPUT47_35_0_, gt.INPUT_STORE_TOTAL_SALES as INPUT48_35_0_, gt.INPUT_STORE_TOTAL_SURPLUS as INPUT49_35_0_, gt.INPUT_STORE_TOTAL_REG_HOURS as INPUT50_35_0_, gt.CALC_STORE_TOTAL_HRS_INC_ADMIN as CALC51_35_0_, gt.INPUT_SUPPLEMENTAL_FLAG as INPUT52_35_0_, gt.INPUT_REGION_ID as INPUT53_35_0_, gt.INPUT_REGION_ABBREV as INPUT54_35_0_, gt.INPUT_REGION_NAME as INPUT55_35_0_, gt.INPUT_STORE_ID as INPUT56_35_0_, gt.INPUT_STORE_ABBREV as INPUT57_35_0_, gt.INPUT_STORE_NAME as INPUT58_35_0_, gt.INPUT_PS_STORE_ID as INPUT59_35_0_, gt.INPUT_SUB_STORE_ABBREV as INPUT60_35_0_, gt.INPUT_SUB_STORE_NAME as INPUT61_35_0_, gt.INPUT_SUB_PS_STORE_ID as INPUT62_35_0_, gt.INPUT_STORE_LIVE_ON_GS_FLAG as INPUT63_35_0_, gt.OUTPUT_TEAM_SALES as OUTPUT64_35_0_, gt.OUTPUT_REG_LABOR_HOURS as OUTPUT65_35_0_, gt.OUTPUT_OT_LABOR_HOURS as OUTPUT66_35_0_, gt.OUTPUT_LABOR_COST as OUTPUT67_35_0_, gt.OUTPUT_LABOR_BUDGET as OUTPUT68_35_0_, gt.INPUT_COUNTRY_CODE as INPUT69_35_0_, gt.INPUT_STORE_TEAM_FLAG as INPUT70_35_0_, gt.INPUT_STORE_NON_GS_ADMIN_HRS as INPUT71_35_0_ FROM GS_TEAM gt inner join TEAM_DETAIL td ON td.team_id = gt.team_id AND td.DRAFT_GS_TEAM_ID = gt.gs_team_id inner join TEAM t ON t.team_id = td.team_id inner join STORE s ON s.store_id = t.store_id WHERE (s.store_id = 9000 OR s.parent_store_id = 9000) AND td.fiscal_period_id = 70
The ERROR is
Code:
WARN [11-21-2005 18:07:52] (JDBCExceptionReporter.java:String;)V:71) - SQL Error: 17006, SQLState: null
ERROR [11-21-2005 18:07:52] (JDBCExceptionReporter.java:String;)V:72) - Invalid column name
ERROR [11-21-2005 18:07:52] (CalcIterator.java:String;:152) - org.hibernate.exception.SQLGrammarException: could not execute query
So what am I doing wrong??
Thanks!
Atul