From: Max R. A. (JIRA) <no...@at...> - 2006-05-10 10:03:27
|
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1452?page=all ] Max Rydahl Andersen closed HHH-1452: ------------------------------------ Fix Version: 3.2.0 Resolution: Fixed fixed afaik. just need to use <return-join>. > Native SQL query is missing join if entity includes many-to-one on secondary table > ---------------------------------------------------------------------------------- > > Key: HHH-1452 > URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1452 > Project: Hibernate3 > Type: Bug > Components: core > Versions: 3.1.2 > Reporter: Christian Bauer > Priority: Minor > Fix For: 3.2.0 > > > Mapping of a many-to-one across a join table: > <class name="Item"> > <join table="ITEM_BUYER" > optional="true"> > <key column="ITEM_ID"/> > <many-to-one name="buyer" column="USER_ID"/> > </join> > </class> > Query: > result = session.createSQLQuery("select {i.*} from ITEM i" + > " join USERS u on i.SELLER_ID = u.USER_ID" + > " where u.USERNAME = :uname") > .addEntity("i", Item.class) > .setParameter("uname", "turin") > .list(); > Generated SQL and exception: > Hibernate: > /* dynamic native SQL query */ select > i.ITEM_ID as ITEM1_7_0_, > i.OBJ_VERSION as OBJ2_7_0_, > i.NAME as NAME7_0_, > i.DESCRIPTION as DESCRIPT4_7_0_, > i.INITIAL_PRICE as INITIAL5_7_0_, > i.INITIAL_PRICE_CURRENCY as INITIAL6_7_0_, > i.RESERVE_PRICE as RESERVE7_7_0_, > i.RESERVE_PRICE_CURRENCY as RESERVE8_7_0_, > i.START_DATE as START9_7_0_, > i.END_DATE as END10_7_0_, > i.STATE as STATE7_0_, > i.APPROVAL_DATETIME as APPROVAL12_7_0_, > i.CREATED as CREATED7_0_, > i.APPROVED_BY_USER_ID as APPROVED14_7_0_, > i.SELLER_ID as SELLER15_7_0_, > i_1_.USER_ID as USER2_2_0_, > 'T' as formula0_0_, > i.ITEM_ID as formula1_0_ > from > ITEM i > join > USERS u > on i.SELLER_ID = u.USER_ID > where > u.USERNAME = ? > 03:45:18,243 WARN JDBCExceptionReporter:71 - SQL Error: -28, SQLState: S0022 > 03:45:18,244 ERROR JDBCExceptionReporter:72 - Column not found: I_1_.USER_ID in statement [/* dynamic native SQL query */ select i.ITEM_ID as ITEM1_7_0_, i.OBJ_VERSION as OBJ2_7_0_, i.NAME as NAME7_0_, i.DESCRIPTION as DESCRIPT4_7_0_, i.INITIAL_PRICE as INITIAL5_7_0_, i.INITIAL_PRICE_CURRENCY as INITIAL6_7_0_, i.RESERVE_PRICE as RESERVE7_7_0_, i.RESERVE_PRICE_CURRENCY as RESERVE8_7_0_, i.START_DATE as START9_7_0_, i.END_DATE as END10_7_0_, i.STATE as STATE7_0_, i.APPROVAL_DATETIME as APPROVAL12_7_0_, i.CREATED as CREATED7_0_, i.APPROVED_BY_USER_ID as APPROVED14_7_0_, i.SELLER_ID as SELLER15_7_0_, i_1_.USER_ID as USER2_2_0_, 'T' as formula0_0_, i.ITEM_ID as formula1_0_ from ITEM i join USERS u on i.SELLER_ID = u.USER_ID where u.USERNAME = ?] -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |