• 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

Composite Key Issues

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following datamodel: (Apologies if the Kleene shorthand isn't in preferred format)

Order 1 => * Credit
Order * => 1 LoanPopulation
LoanPopulation 1 => + Loan
Loan 1 => * Credit

Now, the problem is that for a given object graph (say, I want to fetch an Order and its associated components) the Credit object is uniquely keyed on order_id and loan_id.

The net-net of this is that I can create a DAO that will fetch this object by supplying the two keys explicitly (obviously) but I cannot seem to set up a mapping that will allow Hibernate to automatically load the appropriate one because of the composite dependency (ie, I can load the Order, then the Loan Population, then the Loans, but to get Credit, I need the order_id which isn't a column in Loan that I can join on).

Any help much appreciated.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Michael ,

The PK of tabel Credit is composed of both columns order-Id & loan_id.
let credit_id is surrogate primary key.For this we can use <idbag> mapping,

<idbag name="credits" table="Credit">
<collection-id type="long" column="credit_id">
<generator class="sequence"/>
</collection-id >
<key column="order_id"/>
<many-to-many class="Loan" column="load_id"/>
</idbag>
u can use other collections as well
so ,u have now order_id to get credits..
regards,
yakub
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic