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 many-to-many association problem 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 "many-to-many association problem" Watch "many-to-many association problem" New topic
Author

many-to-many association problem

Raj Gowda
Greenhorn

Joined: Sep 18, 2007
Posts: 4
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...
John Grath
Greenhorn

Joined: Sep 18, 2007
Posts: 15
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: many-to-many association problem
 
Similar Threads
Problem for fetching results from 2 tables which do not have relation...
one to many concepts
How to create Entity bean relationship for this?
EJB without primary key in Database
Auto-generated ID number