使用JPA查询OneToMany

时间:2019-12-28 13:09:22

标签: hibernate spring-boot spring-mvc jpa

嗨,我是春季新手,正在学习教程。我下面有两个具有一对多关系的实体。我想获取建筑物的所有呼叫点。我应该在建筑物存储库还是在呼叫点存储库中执行此操作?我已经在使用buildid的呼叫点存储库中尝试过,但是看到以下错误。谢谢

@Entity
public class BuildingEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int buildingid;

@Column(name="name", nullable=false)
private String name;

@Column(name="address")
private String address;

@Column(name="postcode")
private String postcode;

@Column(name="telephone")
private String telephone;

@OneToMany(mappedBy = "building", fetch = FetchType.LAZY)
private List<CallpointEntity> callpoints;

}

@Entity
public class CallpointEntity {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;

@Column(name="number")
private int number;

@Column(name="location")
private String location;

@Column(name="comment")
private String comment;

@ManyToOne
@JoinColumn(name="buildingid")
private BuildingEntity building;

}

使用呼叫点存储库时出错。

  

未找到CallpointEntity类型的属性buildingid!你是说“建筑”吗?

0 个答案:

没有答案