Java 如何将此UML转换为JPA实体
我有这个UML图 我试图构建这样的实体(我将Java 如何将此UML转换为JPA实体,java,jpa,Java,Jpa,我有这个UML图 我试图构建这样的实体(我将Entity类重命名为Entidad) RelationshipType.java @Entity @Table(name = "relationship_type") public class RelationshipType { @Id @GeneratedValue private Long id; private String type; @OneToMany(mappedBy = "relati
Entity
类重命名为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
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>();
现在,我不知道问题出在哪里,需要做好这项工作,因为我正在使用这些实体来构建DB模式。我认为这是另一种情况,在这个问题中,我有两个来自同一个实体中关系的电话。你可以逐一注释这些行,并确认错误是否是由多对一引起的:@ManyToOne private relations@OneToMany(mappedBy=“entity”,fetch=FetchType.EAGER)私有集关系=newhashset()@amitmahajan是的,如果我评论
@manytone私人关系相关代码>并在RelationshipType中实现可序列化它可以工作,但我想我需要这个字段,但我不确定(我从来没有使用UML图…)我现在已经很久没有使用hibernate了。据我所知,问题是因为hibernate无法将实体与关系联系起来。您可能需要在ManyTone批注上指定一个列属性。我想这是另一种情况,在这个问题中,我有两个来自同一实体中关系的调用。您可以逐个注释这些行,并确认错误是否是由于多对一造成的:@ManyTone private Relationship related@OneToMany(mappedBy=“entity”,fetch=FetchType.EAGER)私有集关系=newhashset()@amitmahajan是的,如果我评论@manytone私人关系相关代码>并在RelationshipType中实现可序列化它可以工作,但我想我需要这个字段,但我不确定(我从来没有使用UML图…)我现在已经很久没有使用hibernate了。据我所知,问题是因为hibernate无法将实体与关系联系起来。您可能需要在ManyTone注释上指定列属性。
@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>();
Foreign key (FK_9d8afoh1pv9r59iwjkbcpnud1:entity [])) must have same number of columns as the referenced primary key (relationship [relationshipType_id,entity_id])