假设我有以下结果集:

所以,我们这里有一对多对多的关系。问题是,在Hibernate中对其进行分组并将此数据结构转换为DTO的最佳方式是什么,字段如下:
String countryName String companyName List invoiceNumbers
谢谢!
发布于 2015-02-24 19:38:33
适用于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
}https://stackoverflow.com/questions/28694152
复制相似问题