-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Replacing a M-1 relationship by M-N relationship
PostPosted: Thu Jun 30, 2016 9:50 am 
Newbie

Joined: Thu Jun 30, 2016 9:30 am
Posts: 4
Hi guys!

I am a newbie here, I am using Hibernate for the first time, and I have many issues with it.

Before I had A table let's call it T_1, that countains a lot of elements wich are in relationship with each other. For exemple a table called Person and a A, B and C are children of D the father. In this case it is a M-1 relationship, those relationship are stocked in a table T_2 (ggd_id, id) the association Person-Person (Children-Father).

My code was like this:
Code:
@Audited(withModifiedFlag=true)
@Entity
@SecondaryTable(name = "T_2")
public abstract class T_2{
@Audited(targetAuditMode=RelationTargetAuditMode.NOT_AUDITED)
   @ManyToOne(fetch=FetchType.EAGER)
   @JoinColumns(
   @JoinColumn(name = "ggd_id", referencedColumnName = "id", table="T_2")
   )
   protected GGD ggd;
...}


But a children has father and mother, so the relationship is M-N, I tried to replace the annotation with @ManytoMany but I cannot extract GGD from the database.

This is the code:

Code:
@Audited(withModifiedFlag=true)
@Entity
@SecondaryTable(name = "T_2")
public abstract class T_2{
@Audited(targetAuditMode=RelationTargetAuditMode.NOT_AUDITED)
   @ManyToMany(fetch = FetchType.EAGER)
   @JoinTable(name = "T_2", joinColumns = {
         @JoinColumn(name = "ggd_id", nullable = false, updatable = false) }, inverseJoinColumns = {
               @JoinColumn(name = "id", nullable = false, updatable = false) })
   protected Set<GGD> ggd;
...}


Is this right or should I change this mapping, I really don't know what to do.
I don't know if you need more information, but I'm here for any question.
Thank you in advance.


Top
 Profile  
 
 Post subject: Re: Replacing a M-1 relationship by M-N relationship
PostPosted: Thu Jun 30, 2016 11:07 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
It's very difficult to follow with all those obfuscated names. Also, why the abstract classes and the secondary collections. When it comes to mapping, the simpler the better.
Check out the examples in the Hibernate docs and you'll surely find your answer.


Top
 Profile  
 
 Post subject: Re: Replacing a M-1 relationship by M-N relationship
PostPosted: Fri Jul 01, 2016 3:20 am 
Newbie

Joined: Thu Jun 30, 2016 9:30 am
Posts: 4
Thank you for your reply, well the class is abstract because there are 2 classes which extend this class. I'm not the responsible of this conception :(
Concerning my problem, this code insert values of ggd_id in id and id in ggd id, I tried to replace ggd_id and id in the code but I got ggd_id missing column in T1.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.