我现在的问题是!公司和公司行业是多对多的关系。在做关系映射时分成了两个一对多的关系,所以就有了中间表。 公司行业
public class Industry implements java.io.Serializable {
private Integer industryId;
/**行业与公司的中间映射表*/
private Set<CompanyIndustryRef> companyIndustryRefs = new HashSet<CompanyIndustryRef>(0); 公司行业中间表
public class CompanyIndustryRef implements java.io.Serializable {
        private Integer companyIndustryRefId;
private Company company;
private Industry industry;  公司实体
 public class Company implements java.io.Serializable {
private Integer companyId;
/**公司行业中间表*/
private Set<CompanyIndustryRef> companyIndustryRefs = new HashSet<CompanyIndustryRef>(0);
现在我在页面保存一个公司时,同时需要保存公司行业,在action中可以得到一组
List<Industry> listIndustry = new ArrayList<Industry>();//公司行业
 公司行业,但是公司需要的是中间的companyIndustryRefs ,怎么转换!

解决方案 »

  1.   

    同样save()中间表实体
    给中间表的两个属性:company和industry赋值
    Company com= new Company();
    com.set()..
    Industry ind= new Industry ();
    ind.set()..
    companyIndustryRef.setCompany(com); 
    companyIndustryRef.setIndustry(ind);
    再用save(companyIndustryRef) ;
      

  2.   

    同样save()中间表实体
    给中间表的两个属性:company和industry赋值
    Company com= new Company();
    com.set()..
    Industry ind= new Industry ();
    ind.set()..
    companyIndustryRef.setCompany(com);  
    companyIndustryRef.setIndustry(ind);
    再用save(companyIndustryRef) ;