s1sh(struts1+spring+hibernate)整合过程中遇一些的问题

本文总结了使用Hibernate框架过程中常见的六个问题及解决方案,包括HQL语法错误、数据源配置问题、配置文件路径错误等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 使用hql语句时的报错: org.hibernate.hql.internal.ast.QuerySyntaxException: USER is not mapped 报错解决
原因:
这个错误的原因在于from后面接的应该是类名(User),而不是表名(USER)。
我的hql语句是
String hql = “from user”;
解决:
所以正确的写法是String hql = “from User”

2. 在hbm.xml中的table名报错: Cannot resolve table 根据提示assign data Source,发现dataSource中提示default or no dataSource
原因:
经过检查发现是我之前更改了jdbc的驱动但之前那个没有删除,导致一直引入的都是错误的驱动
解决:
参照https://www.cnblogs.com/yinze/p/13894069.html

3. 配置文件中的报错:Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/action-servlet.xml]
原因:
原因在于contextConfigLocation属性是否配置写错了
解决:
检查struts-config.xml

<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="ContextConfigLocation" value="/WEB-INF/applicationContext.xml"/>
</plug-in>

ContextConfigLocation的头字母“C"是大写的。改成小写,重启系统。异常信息没有了。

4. applicationContext.xml中的sessionFactory配置错误导致:Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property ‘dataSource’: no matching editors or conversion strategy found
原因:
在applicationComtext.xml中dataSource的引用错误

解决:
把value改成ref即可

5. Spring注入一直失败,bean写的也没有问题
可能原因:
在struts-config.xml文件中配置action时没有把actionBean的创建交给spring来管理
解决:
将type的值改为以下即可
type=“org.springframework.web.struts.DelegatingActionProxy”

6. 使用hibernateTemplate报错 getsession方法找不到
原因:
import的hibernate版本(hibernate3)与pom中导入的hibernate版本(hibernate4)不一致
hibernateTemplete只有在hibernate3以下支持,在hibernate4以上不支持,
原因是hibernate4已经开始支持事务管理会与hibetnateTemplete冲突
解决:
在pom.xml中将hibernate版本更改为hibernate3.X(我改成了3.5.1-Final)即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值