[SSH]关于AfterReturningAdvice的一个问题!!高手速进!!!

foxinmy 2011-03-21 02:34:10
问题描述:在AfterReturningAdvice的实现类的afterReturning方法中查询失败
spring配置

<!-- TransactionManager -->
<bean id="hibTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="hibTransactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="select*" propagation="REQUIRED"/>
<tx:method name="search*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="do*" propagation="REQUIRED" />
<tx:method name="*" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut expression="execution(* biz.*.*(..))"
id="bizMethods" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="bizMethods" />
</aop:config>
<!--
********************************我是很长的分割线********************************
-->
<!-- Dao -->
<bean id="petDiaryDao" class="dao.impl.hib.PetDiaryDaoHibImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="petInfoDao" class="dao.impl.hib.PetInfoDaoHibImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!--
********************************我是很长的分割线********************************
-->
<!-- Biz -->
<bean id="petDiaryBizTarget" class="biz.impl.PetDiaryBizImpl">
<property name="petDiaryDao" ref="petDiaryDao" />
</bean>
<bean id="petInfoBizTarget" class="impl.PetInfoBizImpl">
<property name="petInfoDao" ref="petInfoDao" />
</bean>
<!--
********************************我是很长的分割线********************************
-->
<!-- Advice -->
<bean id="lotteryAdvice" class="advice.LotteryAdvice">
<property name="petInfoBiz" ref="petInfoBizTarget" />
</bean>

<bean id="petInfoBiz" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces" value="biz.PetInfoBiz" />
<property name="interceptorNames" value="lotteryAdvice" />
<property name="target" ref="petInfoBizTarget" />
</bean>
<bean id="petDiaryBiz" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="ProxyInterfaces" value="biz.PetDiaryBiz" />
<property name="interceptorNames" value="lotteryAdvice" />
<property name="target" ref="petDiaryBizTarget" />
</bean>


LotteryAdvice类

private PetInfoBiz petInfoBiz = null;

public void setPetInfoBiz(PetInfoBiz petInfoBiz) {
this.petInfoBiz = petInfoBiz;
}

public void afterReturning(Object resultValue, Method method,
Object[] args, Object target) throws Throwable {
PetDiary petDiary = (PetDiary)args[0];
PetInfo petInfo = this.petInfoBiz.selectPetInfo(petDiary.getPetInfo().getPetId());//这里petInfo的值全部为空,并且SQL语句也不输出(petId有值,且在数据库中存在)
petInfo.setPetCute(petInfo.getPetCute()+10);
petInfo.setPetLove(petInfo.getPetLove()+10);
this.petInfoBiz.updatePet(petInfo);
System.out.println("["+petInfo.getPetName()+"]聪明+10,爱心+10");

}

selectPetInfo方法

public PetInfo select(int pid) {
return (PetInfo) super.getHibernateTemplate().get(PetInfo.class, pid);
}

结果报null异常
org.springframework.dao.DataIntegrityViolationException: not-null property references a null or transient value: entity.PetInfo.petName; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: entity.PetInfo.petName


最后说明:在其她类调用该方法能取到值!!郁闷啊、谁能告诉我!!
...全文
164 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ftssyang 2011-09-01
  • 打赏
  • 举报
回复
提示很明确 ,entity.PetInfo.petName 这个字段不允许为空 你查询出数据这个petName有null的数据


小笨熊 2011-09-01
  • 打赏
  • 举报
回复
lz这个错误org.springframework.dao.DataIntegrityViolationException,太明显了。。。

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧