搭建SSH项目框架遇到的错误
myEclipse
Preferences——java——Edit——Templates 设置模板代码
1、用hibernate连接数据库时出现了如下错误:
org.hibernate.MappingException: Could not determine type for: String,at table:spo_text,for columns: [org.hibernate.mapping.Column(spo_remark)]
根据错误提示找到对应的配置文件,最终发现错误根源在
<discriminator column="animal_type" type="String"/>
“String”是java的数据类型,Hibernate中对应的数据类型是”string”,在书写hibernate的配置文件时,要么使用”string”,要么使用”java.lang.String”。
2、
java.lang.IllegalArgumentException: node to traverse cannot be null!
问题解决: 出现这种问题是因为HQL语句出现问题,引起内部查询对象为空,无法处理为空值引起的。
解决方法: 检查HQL语句,还有字符串连接处的空格(尤其是关键字)。
3、在搭建spring4.2.4进行junit4测试时出现错误:
[_java.lang.ExceptionInInitializerError]
解决:版本问题,用的是spring4.2.4.RELEASE和junit4.8,显然springtest需要最少Junit4.9,更换了Junit4.9,瞬间所有问题都没了,参考博客地址:
(http://blog.csdn.net/guanwangzhe521/article/details/51470241)
4、测试hibernate时报错:
org.hibernate.TransactionException: Transaction not successfully started
session关闭不会报这个错,这个错一般都是因为事务没有开始就提交或者回滚事务造成的
//手动事务时,没有加上begin()方法
session.getTransaction().begin();
5、spring和hibernate整合时出错:
java.lang.IllegalStateException: Failed to load ApplicationContext
spring配置文件:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!-- 加载hibernate配置文件 -->
<property name="configLocation" value="classpath:hibernate.cfg.xml"> </property>
</bean>
将dataSource写成dateSource,所以出错
6、整合时,struts2中
Dispatcher initialization failedjava.lang.RuntimeException: java.lang.reflect.InvocationTargetException
由于struts2与hibernate的jar包中javassist-3.18.1-GA.jar有重复,所以删去struts2中jar后,在web—inf下lib中加入javassist-3.18.1-GA.jar可解决问题
7、
Error configuring application listener of class
org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
问题背景:
工程为maven工程,ContextLoaderListener类位于spring-web-3.1.0.RELEASE.jar包中。检查了maven的pom.xml,依赖引入正常。在工程Maven Dependencies视图中也能看到spring-web-3.1.0.RELEASE.jar包被正常引入进来了。
错误原因:
进入到tomcat的部署路径.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\下检查了一下,发现工程部署后在WEB-INF文件夹下没有生成lib目录,正常情况下,会生成lib目录并把工程的所有依赖jar包都部署到该目录下。
解决方案:
1.右键点击项目–选择Properties
选择Deployment Assembly,在右边点击Add按钮,在弹出的窗口中选择Java Build Path Entries,添加所有jar包
2.点击Finish,然后可以看到已经把Maven Dependencies添加到Web应用结构中了操作完后,重新部署工程
8、报错:
org.springframework.orm.hibernate4.HibernateOptimisticLockingFailureException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
解决方法:
检查下SQL语句有没有写错,然后检查下配置文件中主键的自增配置有没有搞错
9、在jQuery导入到 Myeclipse里,结果就出现了 红叉
解决方案:
右击 jquery-2.1.1.min.js –>MyEclipse –>
①先点击Exclude From Validation ;②点击Run Validation 即可。
10、
org.hibernate.LazyInitializationException could not initialize proxy - no Session