我有两个实体Equipement
,Company
像这样:
public class Equipement{
String type ;
Company company ;
@ManyToOne(cascade = CascadeType.ALL)
public Company getCompany(){
return this.company ;
}
}
public class Company{
// fields getters setters ..
}
每个Equipement
都是从 a 购买的Company
,我需要创建Company
然后将其注入Equipement
Session session = SessionFactory.openSession() ;
Transaction tx = session.beginTransaction() ;
Equipement equipement = new Equipement() ;
Company company = new company() ;
equipement.setCompany(company) ;
session.save(equipement) ;
tx.commit() ;
session.close() ;
这给了我一个例外
TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: org.marsamaroc.mmapp.domain.Company