I solved it doing this:
Code:
@Entity
@Table
public class A
{
...
private int id;
...
private Set<ARelationship> relationshipsOwner; //Relationships as Owner
private Set<ARelationship> relationshipsRelated; //Relationships as Related
...
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(unique = true, nullable = false)
public int getId()
{
return this.id;
}
...
@OneToMany(fetch = FetchType.LAZY, mappedBy = "owner")
public Set<A> getRelationshipsOwner()
{
return this.relationshipsOwner;
}
...
@OneToMany(fetch = FetchType.LAZY, mappedBy = "related")
public Set<A> getRelationshipsRelated()
{
return this.relationshipsRelated;
}
...
}
@Entity
@Table
public class ARelationship
{
...
private int id;
private A owner;
private A related;
...
private TypeX typeX;
...
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(unique = true, nullable = false)
public int getId()
{
return this.id;
}
...
@ManyToOne(fetch = FetchType.LAZY, optional = false)
public A getOwner()
{
return this.owner;
}
...
@ManyToOne(fetch = FetchType.LAZY, optional = false)
public A getRelated()
{
return this.related;
}
...
}
Thanks!