I have this UML diagram.
And I tried to build entities like this (I renamed Entity
class to Entidad
)
RelationshipType.java
@Entity
@Table(name = "relationship_type")
public class RelationshipType {
@Id
@GeneratedValue
private Long id;
private String type;
@OneToMany(mappedBy = "relationshipType", fetch = FetchType.EAGER)
private Set<Relationship> relationships = new HashSet<Relationship>();
//Getters and Setters
Relationship.java
@Entity
@Table(name = "relationship")
public class Relationship {
@Id
@ManyToOne
private RelationshipType relationshipType;
@Id
@ManyToOne
private Entidad entity;
//Getters and Setters
Entidad.java
@Entity
@Table(name = "entity")
public class Entidad {
@Id
@GeneratedValue
private Long id;
private String image;
private String foundationNotes;
private String alias;
private Boolean excludeNotifications;
private String notes;
//[...]
@ManyToOne
private Relationship related;
@OneToMany(mappedBy = "entity", fetch = FetchType.EAGER)
private Set<Relationship> relationships = new HashSet<Relationship>();
But when I launch app throws this:
Foreign key (FK_9d8afoh1pv9r59iwjkbcpnud1:entity [])) must have same number of columns as the referenced primary key (relationship [relationshipType_id,entity_id])
At now, I don't know where is the problem and need do this well because I'm using this entities to build the DB schema.