一、super.getHibernateTemplate()execute(HibernateCallback)
错误信息:
The method execute(HibernateCallback
发生错误的代码:
@Override public List
原来是包引用错误,引入包的时候一定要小心哦,我是把所有的spring、Hibernate包都添加进工程了,引入的时候一定要注意:
import org.springframework.orm.hibernate3.HibernateCallback;import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
看出来了吧,一个时hibernate3一个时hibernate5,版本不一致怎么接受这样的参数。我使用的hibernate版本是4.3.9。所有都改成
import org.springframework.orm.hibernate4.HibernateCallback;import org.springframework.orm.hi
事务配置的问题;报错信息里面写的很清楚了;
看下你DAO的事务是怎么控制的;贴出代码;
比较合理的实践是在你的SERVICE控制事务;而不是在DAO层;
解决这个问题应该不难。
1.Hibernate 常见异常
net.sf.hibernate.MappingException
当出现net.sf.hibernate.MappingException: Error reading resource:…异常时一般是因为映射文
件出现错误。
当出现net.sf.hibernate.MappingException: Resource: … not found是因为XML配置文件没找到所致,有可能是放置目录不正确,或者没将其加入hibernate.cfg.xml中。
2. net.sf.hibernate.PropertyNotFoundException
当出现net.sf.hibernate.PropertyNotFoundException: Could not find a setter for property
name in class …时,原因一般是因为XML映射文件中的属性与对应的Java类中的属性的getter或setter方法不一致。
3. org.hibernate.id.IdentifierGenerationException
当出现org.hibernate.id.IdentifierGenerationException: ids for this class
must be manually assigned before calling
save():异常时,一般是因为
素
解决方案:
的取值可以为increment、identity、sequence、hilo、native……等,更多的可参考hibernate参考文档,一般取其值为native 。
hibernate能自动处理RuntimeException,如果是其他的,则要自己进行处理的