IntelliJ Java IDE
The moose likes Object Relational Mapping and the fly likes hbm.xml question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "hbm.xml question" Watch "hbm.xml question" New topic
Author

hbm.xml question

Andy Hahn
Ranch Hand

Joined: Aug 31, 2004
Posts: 225
I have 3 tables: Company, Company_Item and Item. Company_Item holds the relationship between Company and Item. Pretty straight forward.

In my Company.hbm.xml and Item.hbm.xml files I have the following set defined. Notice I do not lazy load the CompanyItems. I load them real time:




In my CompanyItem.hbm.xml file I have the following many-to-ones defined. Notice I do not lazy load the Company and Items. I load them real time:



So my question is this:
If I load a Company and that automatically loads a companyItems set, then when the companyItems loads that triggers a Company to load, does the loading ever end? It seems like it could be an infinite loop. Its like looking in a mirror that faces another mirror - you see back and forth forever.

Company
--CompanyItem
--Company
--CompanyItem
--Company

Is this a problem or is Hibernate smart enough to know to not load everything n times? Thanks
Pierre Henry
Ranch Hand

Joined: Oct 01, 2003
Posts: 31
Answer is ... YES

You have to be carefull It's not a recursive association.

I suggest you try a <many-to-many> tag for your association.


"A good method shouldn't bypass one screen long"<br />"genius is the knowledge left when one has forgotten everything"
 
 
subject: hbm.xml question
 
Threads others viewed
Hibernate- one-to-many association on a foreign key
Problem with Updating Foreign key values
Save objects problem
hibernate one-to-many mapping, inserting associated objects in collection along with parent
Hibernate, User and Address with association table between
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com