[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-1452) Native SQL query is missing join if entity includes many-to-one on secondary table

Razan Abbass (JIRA) noreply at atlassian.com
Sun Oct 10 18:52:59 EDT 2010


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1452?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=38678#action_38678 ] 

Razan Abbass commented on HHH-1452:
-----------------------------------

[cheap airline tickets|http://getflightsto.com]
[Parenting|http://childcareforums.com]


> 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: Hibernate Core
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.1.2
>            Reporter: Christian Bauer
>            Priority: Minor
>             Fix For: 3.2.0.cr3
>
>
> 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

        


More information about the hibernate-issues mailing list