Hibernate中一对多关系中的空数据问题?
gdx 2003-09-28 12:15:58 Hibernate中当存在一对多关系时,如公司--员工的映射,
public class Employee{
Company company;
...
public Company getCompany(){
return company;
}
}
public class Company{
Set employee;
}
Employee映射文件:(Employee.hbm.xml)
<many-to-one
name="company"
class="eg.Company"
cascade="none"
column="company"/>
此时,如果Employee表中company字段中存在与Company表中主键不同的数据或者该项为null,则无法调用employee.getCompany(),返回异常:
net.sf.hibernate.ObjectNotFoundException:
No row with the given identifier exists:
, of class: com.withub.justice.instance.Occupation
请各位Hibernate高手帮忙!