ssh框架中通过id删除关联表子表中的某条数据,结果通过id返回子表数据是空
@RepositorypublicclassBusinessDaoImplextendsHibernateDaoSupportimplementsBusinessDao{...
@Repository
public class BusinessDaoImpl extends HibernateDaoSupport implements BusinessDao {
@Resource
public void setSF(SessionFactory sf) {
super.setSessionFactory(sf);
}
@Override
public void deleteBusiness(Integer id) {
Business business = new Business();
business.setId(id);
System.out.println(business.getId() + "," + business.getAccountId());
getHibernateTemplate().delete(id);
}
}
这个里面的business.getAccountId() = null,这是为什么?通过ID怎么才能获取到这条数据?
我的映射文件Business.hbm.xml:
<hibernate-mapping>
<class name="org.netctoss.entity.Business" table="BUSINESS">
<id name="id" type="integer" column="id">
<generator class="identity">
<param name="identity">BUSINESS_IDE</param>
</generator>
</id>
<property name="unixHost" type="string" column="UNIX_HOST"/>
<property name="osUserName" type="string" column="OS_USERNAME"/>
<property name="loginPassword" type="string" column="LOGIN_PASSWD"/>
<property name="status" type="string" column="STATUS"/>
<property name="createDate" type="date" column="CREATE_DATE"/>
<property name="pauseDate" type="date" column="PAUSE_DATE"/>
<property name="closeDate" type="date" column="CLOSE_DATE"/>
<!-- 配置account属性,采用多对一关系加载相关的account内容 -->
<many-to-one name="account" column="ACCOUNT_ID" fetch="join"
not-null="true" class="org.netctoss.entity.Account"/>
<!-- 配置cost属性,采用多对一关系加载相关的cost内容 -->
<many-to-one name="cost" column="COST_ID" fetch="join"
not-null="true" class="org.netctoss.entity.Cost"/>
</class>
</hibernate-mapping> 展开
public class BusinessDaoImpl extends HibernateDaoSupport implements BusinessDao {
@Resource
public void setSF(SessionFactory sf) {
super.setSessionFactory(sf);
}
@Override
public void deleteBusiness(Integer id) {
Business business = new Business();
business.setId(id);
System.out.println(business.getId() + "," + business.getAccountId());
getHibernateTemplate().delete(id);
}
}
这个里面的business.getAccountId() = null,这是为什么?通过ID怎么才能获取到这条数据?
我的映射文件Business.hbm.xml:
<hibernate-mapping>
<class name="org.netctoss.entity.Business" table="BUSINESS">
<id name="id" type="integer" column="id">
<generator class="identity">
<param name="identity">BUSINESS_IDE</param>
</generator>
</id>
<property name="unixHost" type="string" column="UNIX_HOST"/>
<property name="osUserName" type="string" column="OS_USERNAME"/>
<property name="loginPassword" type="string" column="LOGIN_PASSWD"/>
<property name="status" type="string" column="STATUS"/>
<property name="createDate" type="date" column="CREATE_DATE"/>
<property name="pauseDate" type="date" column="PAUSE_DATE"/>
<property name="closeDate" type="date" column="CLOSE_DATE"/>
<!-- 配置account属性,采用多对一关系加载相关的account内容 -->
<many-to-one name="account" column="ACCOUNT_ID" fetch="join"
not-null="true" class="org.netctoss.entity.Account"/>
<!-- 配置cost属性,采用多对一关系加载相关的cost内容 -->
<many-to-one name="cost" column="COST_ID" fetch="join"
not-null="true" class="org.netctoss.entity.Cost"/>
</class>
</hibernate-mapping> 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询