• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate: Different Join in Save() and Get()

 
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have 2 tables viz. TABLE1 and TABLE2:

TABLE1 has it's PK as {ID}
TABLE2 has composite-id as {A,B,C}... TABLE2 also has a column {D}

TABLE1 and TABLE2 are associated with one-to-one mapping TABLE1.ID=TABLE2.A
Cascade-save is on.

Case1:Save()
I want TABLE1.ID=TABLE2.A and TABLE2.B='1' and TABLE2.C='2'

Case2:Get()
I want TABLE1.ID=TABLE2.A and TABLE2.B='1'and TABLE2.D='4'

How should i define this mapping?
Presently i have done like this :



Save is working fine... but when it comes to Get(), the sql query is:

select *
from TABLE1 t1 left outer join TABLE2 t2 on '1'= t2.A and '2'=t2.B and '3'=t2.C where t1.ID=?

which is incorrect...

Actually i want different joins for save() and get() respectively..... This is possible in JDBC but how i can achieve samething in
Hibernate ?

 
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There seems to be a little problem.

I am wondering how can you have one to one relationship between the two tables, if the PK of one table is mapped to the "part" of the PK of the other table, as in your case.
Doesn't it became a many-to-one relationship?
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rahul Actually there are 2 relationship between Table1 and Table2 <one-to-one> and <one-to-many>
It is the same case as described in "Java Persistence With Hibernate book" : Item and Bid classes.

class Item{
Bid successful;
List bids;
}

The problem is not of association, the main query is

" i want different joins for save() and get() respectively..... This is possible in JDBC but how i can achieve samething in Hibernate ?"

 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure how you can get around this problem.

You may want to create a view from the two tables, and make its definition in such a way that the view returns whatever you are trying to select.
Save() operation on the table should remain the same...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic