假设我有以下结果集:
所以,我们在这里有一对多的关系。 问题是在Hibernate中将它分组并将此数据结构转换为DTO的最佳方法是:
String countryName
String companyName
List invoiceNumbers
谢谢!
答案 0 :(得分:0)
Country
和Company
---- Many-to-Many
对于公司和发票--- One-to-Many
@Entity
public class Country {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
@ManyToMany(mappedBy="countries")
private Collection<Country> countries;
...
getters and setters
}
@Entity
public class Company {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
@ManyToMany
private Collection<Country> countries;
@OneToMany
private Collection<Invoice> invoices;
...
getters and setters
}
@Entity
public class Invoice {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private int invoice_number;
...
getters and setters
}