• 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

many-to-many association problem

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all, i am newbei to Hibernate, i am working on a project, it has two masters one is Being and another one is Debit. in Being master i am storing just beingName, in Debit master i am storing debitName and all the associated beingIds.

i am using three tables to store the content:
being:
beingId long primary key, auto generated
beingName varchar(100)

debit:
debitId long primary key, auto generated
debitName varchar(100)

debit_being:
debitId long forieg key
beingId long forieg key

to persist being details i am using Being.hbm.xml
while user adding a being he will just enter beingName and submits, that will store in being table through Being.hbm.xml file

to persist debit details i am using debit.hbm.xml
while user adding a debit he will enter debitName and select multiple beingNames from the selection list and submits, now the debitName is storing to debit table, then newly generated debitId and associated beingIds are storing in debit_being table.

now when i am listing the debits i need to display debits with associated beingNames rather beingIds so, is it possible to define in the mapping document (i,e Debit.hbm.xml) so that i can retrieve all the associated Being objects of perticular Debit object.
or
do i have to write hql query to join the tables.

any help appriciated.
thanks in advance...
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I understand your question correctly, you most certainly can. In Hibernate you must map the domains using an association. This will enable you to use the session.find or better still the Query object to return the values, i.e session.get(..) and that the objects will be contain references to each other.

An association can be performed using a idbag, set, map, bag for example. Toplink works differently though, where the 'container' maintains the references between objects.

Hope this helps.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic