2015-02-24 53 views
0

假设我有以下结果集:Hibernate的分组和结果集转变

enter image description here

所以,我们有一个一对多一对多的关系在这里。 的问题是,什么是最好的方式,以小组它休眠和转换该数据结构与DTO领域,如:

String countryName String companyName List invoiceNumbers

谢谢!

回答

0

对于CountryCompany ---- 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 

}