我有两个实体
@Entity
@Table(name = "person")
Class Person {
@Id
@Column(name = "id")
private String id ;
private String addressId;
private String name ;
// gets etc...}
和
@Entity
@Table(name = "address")
Class Address {
@Id
@Column(name = "id")
String id ;
String personId ;
String streetId ;
String country ;
// gets etc... }
让我们假设我需要这个地址有很多人,每个人只有一个地址 我想加入Person 仅财产国家 我怎么能得到它?
最后我想要一个pojo
@Entity
@Table(name = "person")
class PersonWithCountry{
@Id
@Column(name = "id")
private String id ;
@Column(name = "name")
private String name ;
@Column(name = "what to write here")
private String country ;
//得到设定 }
}
答案 0 :(得分:0)
使用JPA
注释:
在Person
班级
@ManyToOne(targetEntity = Address.class)
@JoinColumn(name = "id")
private Address address;
在Address
班级
@OneToMany(mappedBy = "address")
private List<Person> persons;