wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes How to join two tables having each two fileds in common? (seems like @OneToMany with 2 joinColumns) 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 having each two fileds in common? (seems like @OneToMany with 2 joinColumns)" Watch "How to join two tables having each two fileds in common? (seems like @OneToMany with 2 joinColumns)" New topic
Author

How to join two tables having each two fileds in common? (seems like @OneToMany with 2 joinColumns)

Alfred Couder
Greenhorn

Joined: Jan 29, 2009
Posts: 6
Hibernate version: 3.0.5
JBOSS Server: 4.3.0.GA
Database: Oracle10G

I am sorry to ask this question because it seems to me as some basics in SQL. Nonetheless I see nothing quite close to it in the books and web sites I am searching in.

so easy in SQL, I thought it expected it to be easy with hibernate ate well.

I have on table linked with many others. First, the DB schema is old and most of the table lacks primary keys (But embedded Id fixed that, thanks!)

Now, all I want is to make two join between table.

I basically have two table A and B. In each table, I have two common fields such as A.field1 = B.field3 and A.filed2 = B.filed4.

this a one-to-many unidirectional relation from A to B : each record from A has many related records in B.

I created an entity EA :



and another EB :



So how do I make my mapping so when I load an entity EA, I can have a list of all related EB? (meaning all EB respecting the joins A.field1 = B.field3 and A.filed2 = B.filed4)?


In the end, everything will be perfect. If it's not perfect, it is not the end.
Alfred Couder
Greenhorn

Joined: Jan 29, 2009
Posts: 6
Thanks to parmendratyagi (on forum.hiernate.org)



This just does the job :

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to join two tables having each two fileds in common? (seems like @OneToMany with 2 joinColumns)
 
Similar Threads
Problems with using property in formula [hibernate]
@ManyToMany, @ManyToOne, Join Tables
Cannot add or update a child row: a foreign key constraint fails JPA/Hibernate
Mapping relationship with partial composite key column
Could not determine type for: java.util.Set