【发布时间】:2015-02-24 11:07:03
【问题描述】:
假设我有以下结果集:
所以,我们这里是一对多对多的关系。 问题是在 Hibernate 中对它进行分组并将此数据结构转换为具有以下字段的 DTO 的最佳方法是:
String countryName
String companyName
List invoiceNumbers
谢谢!
【问题讨论】:
标签: sql hibernate grouping hibernate-mapping
假设我有以下结果集:
所以,我们这里是一对多对多的关系。 问题是在 Hibernate 中对它进行分组并将此数据结构转换为具有以下字段的 DTO 的最佳方法是:
String countryName
String companyName
List invoiceNumbers
谢谢!
【问题讨论】:
标签: sql hibernate grouping hibernate-mapping
对于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
}
【讨论】: