• Post Reply Bookmark Topic Watch Topic
  • New Topic

ManyToMany mapping relationship table is blank (Hibernate newbie)

 
neerav arora
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]
 
Junilu Lacar
Sheriff
Posts: 9354
96
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • 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: 9354
96
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!