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.