2015-02-24 60 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 

}