Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

ManyToMany mapping relationship table is blank (Hibernate newbie)

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all ,

iam working on an app where the association between entities is as follows . Here comment is the owner and iteration and user are the inverse tables . The requirement is -
A user can have many comments similarly a comment can be given by multiple users .
Also an iteration can have multiple comments and a single comment can belong to multiple iterations .

The code is as follows








Now the issue that iam facing is the mapping tables are empty .
Also user.getComment() yields empty set


Before i start my web app my db entity tables prepopulated with dummy values . But during run time when i debug the code user.getcomment returns empty set .

Could anyone please help me out what could be the issue .


New-Doc-1_1.jpg
[Thumbnail for New-Doc-1_1.jpg]
 
Sheriff
Posts: 15815
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off, your design doesn't look right to me. In the case of many-to-many relationships, you usually introduce a Join Table in between so that the relationships become something like this:

Iteration (1) --> (N) Iteration-Comment (N) <-- (1) Comment
User (1) --> (N) User-Comment (N) <-- (1) Comment

The join tables have rows that contain the IDs of the entities that it joins. That is:

Iteration-Comment fields: IterationID + CommentID
User-Comment fields: UserID & CommentID
 
Junilu Lacar
Sheriff
Posts: 15815
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just noticed this but having a list of Iterations and a list of Users in a Comment object just doesn't look right to me.  See my previous comment for an alternative.
 
To avoid criticism do nothing, say nothing, be nothing. -Elbert Hubbard. Please critique this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic