• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate many-to-one association does not work properly

 
Shajid Johnny
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am new to Hibernate. I have a class Category which has many SubCategory. so I have created a bi-directional association like this:
-----------------Category.hbm.xml--------------------------


-----------------SubCategory.hbm.xml--------------------------


I have put a Set of sub categories under the Category class.

the project runs properly, but the problem is: when I want to show all Categories- it produces a table with the sub categories also!

i mean to say- the items under SubCategoryTable are also fetched..

could anyone please help me finding & solving the problem???
 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
set lazy=true in second mapping like:


This will not load the subcategories untill you will not call the subCategories method of category class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic