Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help needed on the following example

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following example is from Beginning Hibernate: From Novice to Professional book,

They say that there is a table called Category and another table called Adverts and the relationship is one (Category) to many (Adverts). The file below is the POJO class for Category table. I'm not able to understand why they say this.adverts = new HashSet(); on Line 1 and again this.adverts = new HashSet(); on line 2 ? Also, why they use Set interface? Why not List?



I appreciate anyones help on this.

Thanks in advance!
 
Raminder Singh
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line 1 - initializing the class level set 'adverts' variable as blank.
Line 2 - When we going to make a category by parameterized constructor providing only title, then again initializing set as blank.
reg: Set, it is because 'A set with no nullable element columns. It will have a primary key consisting of all table columns (ie. key columns + element columns)' - http://www.hibernate.org/hib_docs/v3/api/org/hibernate/mapping/Set.html
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Man I'm still not clear. Can you please elaborate on this?
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any participants for my post above?
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To me, when to use a Set, when a List etc. belongs to "Java in General",
and, in fact, has been discussed there, this thread, for example.
[ September 11, 2007: Message edited by: Edvins Reisons ]
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the link. It was helpful!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic