SSH项目运行异常与解决办法小结

今天就总结一下自己这段时间在学习SSH项目的过程中所遇到的几个小错误,以及最终能够奏效的解决办法
1.错误:java.sql.SQLException: Field 'userId' doesn't have a default value
原因与解决:把配置文件的主键改为<generator class="assigned" /> 可以进行自定义主键值,因为我在设主键时没有设成自动增长的,要求填默认值是受了配置文件里<generator class="native"/>的影响了。

2.错误:org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted
object from associations)
解决:
方法1 删除Set方的cascade
方法2 解决关联关系后,再删除

3.错误:org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save():
原因与解决:ID在数据库中应该是自增长列,而在User.hbm.xml中却没有定义成自增长列,在插入数据库时,也就是Save()方法时,出现错误。这样改:
       <id name="id" type="java.lang.Integer">
            <column name="ID" />
            <generator class="increment" />
        </id>

4.org.hibernate.LazyInitializationException: could not initialize proxy - no Session
原因:没有设置lazy属性

5.)Connections could not be acquired from the underlying database
原因:大概的意思是说:不能连接当前所配置的数据库,检查你的URL链接字符串是否正确

猜你喜欢

转载自chenglongup-126-com.iteye.com/blog/1124651