开发者

SQL "column ambiguously defined"- when run from hibernate

When I run a SQL query from sqldeveloper , it runs fine When I run the same query from Hibernate SQL session, it gives me: "ORA-00918: column ambiguously defined" error.

Dies hibernate generate any kind of sql logs that can be used to debug the error?

Edit: here is the sql:(works fine from sqldeveloper)

    SELECT main_contact.cont_name,
  sub_contact.cont_name,
  main_contact.cont_role_desc,
  main_contact.cont_start_dte,
  main_contact.cont_end_dte,
  main_contact.cont_id,
  sub_contact.cont_id,
  main_contact.lookup_desc,
  main_contact.cont_role_desc 
FROM 
  (SELECT cont_rlat.cont_rlat_id ,
    cont_role.cont_role_desc ,
    cont.cont_name ,
    cont.cont_ty_cde ,
    cont.cont_sid ,
    cont.cont_id ,
    cont_rlat.rlat_from_dte ,
    cont.cont_start_dte ,
    cont.cont_end_dte ,
    cont_rlat.app_id ,
    lookup_data_mgmt.lookup_desc
  FROM cont_rlat join
    cont on cont_rlat.cont_sid 开发者_如何学Python     = cont.cont_sid
     join cont_role on cont_rlat.cont_role_id=cont_role.cont_role_id
   join  app on cont_rlat.app_id     = app.app_ID
     join LOOKUP_DATA_MGMT on app.app_TY_CDE    = LOOKUP_DATA_MGMT.LOOKUP_ID
   where 
 app.app_id        =:investmentProfileCId
  ) main_contact left join 
  (SELECT cont.cont_id,
    cont.cont_name,
    cont_sub_rlat.cont_rlat_id
  FROM cont_sub_rlat join 
    cont on   
   cont_sub_rlat.individual_cont_id = cont.cont_sid
  ) sub_contact on 

 main_contact.cont_rlat_id = sub_contact.cont_rlat_id


You're selecting main_contact.cont_role_desc twice. Also, you have two columns called 'cont_name' and two columns called 'cont_id', which also might not make it happy. If dropping the extra cont_name doesn't work, maybe try aliasing those?

SELECT main_contact.cont_name,
  sub_contact.cont_name AS sub_cont_name,
  main_contact.cont_role_desc,
  main_contact.cont_start_dte,
  main_contact.cont_end_dte,
  main_contact.cont_id,
  sub_contact.cont_id AS sub_cont_id,
  main_contact.lookup_desc

Neither of those will be a problem in SQLDeveloper, but I imagine that at the very least having two exact copies of main_contact.cont_role_desc in the result set will be confusing Hibernate -- how will it tell them apart?


in hibernate.cfg.xml to make it log sql statements

<property name="hibernate.show_sql">true</property>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜