This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes How to join two tables on columns that have different names? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to join two tables on columns that have different names?" Watch "How to join two tables on columns that have different names?" New topic
Author

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

Steve Vittoria
Ranch Hand

Joined: Jan 12, 2005
Posts: 33

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

Joined: May 01, 2008
Posts: 66
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


Naresh Waswani
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to join two tables on columns that have different names?
 
Similar Threads
Many to One instead of One to One relationship
Outer join between 3 entities in HQL
jpa problem
Integrity constraint in Hibernate
EntityManager.persist(obj) is not actually storing the object in Database