Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to join two tables on columns that have different names?

 
Steve Vittoria
Ranch Hand
Posts: 35
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I'm trying to join two tables that have different column names.





These two tables need to be joined on OWORD_CODE.CODE = OWORD_LANGUAGE = RESOURCE_KEY, but I'm have difficulties doing that. If the columns were named the same, it works fine.

Here is my class for the OWORD_CODE table...


Here is my class for the OWORD_LANGUAGE table...


Here is the code I'm using to retrieve the data...


I get the following error...

ERROR [JDBCExceptionReporter] ORA-00904: "OWORDLANGU0_"."CODE": invalid identifier

and when I look at the logs, I see the select statement that was generated has the column code in the OWORD_LANGUAGE table, but that table does not have a column named code.




What am I doing wrong here?
 
Waswani Naresh
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Steve,



The above mapping conveys to the Hibernate framework that in the OWORD_LANGUAGE table, there is a column with the name "CODE" that will be used for joining with OWORD_CODE table.

But you do not have "CODE" column in the OWORD_LANGUAGE.

So the solution is to specify that column of the OWORD_LANGUAGE that will contain the OWORD_CODE.CODE value.


Regards,
Naresh Waswani
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic