SSH异常解决
2016-11-13 12:31
197 查看
SSH异常整理
一、org.hibernate.lazyinitialzationException:failed to lazily initialize a collection of role:com.xxx.spring.Customer.linkMans could not initialize proxy -no session
延迟初始化加载异常:
错误原因一般有两个:
1.使用hibernate查询时调用了load方法
2.查询某个对象的关联对象的时候。
解决方式:
1.使用get方法(不推荐使用该方式解决该问题,没有延迟加载效果)
2. 在web.xml文件中 解决延迟加载问题的过滤器,加载struts核心过滤器前面
二、org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘transactionManager’ defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type [java.lang.String] to required type [org.hibernate.SessionFactory] for property ‘sessionFactory’; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.hibernate.SessionFactory] for property ‘sessionFactory’: no matching editors or conversion strategy found
at
创建实体异常:
我出现该问题的原因是在配置事务管理器的时候,将property属性的写成了
三、PropertyNotFoundException:属性找不到异常
Caused by: org.hibernate.PropertyNotFoundException: Could not locate getter method for property [com.xxx.spring.domain.Customer#linkmans]
at org.hibernate.internal.util.ReflectHelper.findGetterMethod(ReflectHelper.java:400)
原因:实体类中的名称大小写不一致
四、QueryParameterException:查询参数异常
org.hibernate.QueryParameterException: Position beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based! Position: 2
解决方式:记住Hibernate的SQL—-索引的参数值是从0开始的。
五、GenericJDBCException:通用JDBC异常
org.hibernate.exception.GenericJDBCException: could not execute statement
Caused by: java.sql.SQLException: Field ‘gid’ doesn’t have a default value
原因:外键gid没有默认值,可能在设置主键生成策略没有对应实体类的数据类型
解决方法:如果数据库表中数据类型为Integer,可设置为主键生成策略为increment、native、assign、identity
六、IdentifierGenerationException:标识符产生异常:
org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.xxx.domain.Customer
解决方式:主键id一定需要手动设置(可能在映射文件忘记写主键生成策略)
七、ConstraintViolationException:约束违背异常
org.hibernate.exception.ConstraintViolationException: could not execute statement
造成原因:主键冲突,主键已经存在。
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry ‘2-1’ for key ‘PRIMARY’
解决方法:多对多级联查询,没有释放外键维护权 在对应的映射文件里添加 inverse属性为ture
一、org.hibernate.lazyinitialzationException:failed to lazily initialize a collection of role:com.xxx.spring.Customer.linkMans could not initialize proxy -no session
延迟初始化加载异常:
错误原因一般有两个:
1.使用hibernate查询时调用了load方法
2.查询某个对象的关联对象的时候。
解决方式:
1.使用get方法(不推荐使用该方式解决该问题,没有延迟加载效果)
2. 在web.xml文件中 解决延迟加载问题的过滤器,加载struts核心过滤器前面
<filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping>
二、org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘transactionManager’ defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type [java.lang.String] to required type [org.hibernate.SessionFactory] for property ‘sessionFactory’; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.hibernate.SessionFactory] for property ‘sessionFactory’: no matching editors or conversion strategy found
at
创建实体异常:
我出现该问题的原因是在配置事务管理器的时候,将property属性的写成了
<property name="sessionFactory" value="sessionFactory"></property>,这里要是一个ref(外部连接对象),将value改成ref就没问题了。
三、PropertyNotFoundException:属性找不到异常
Caused by: org.hibernate.PropertyNotFoundException: Could not locate getter method for property [com.xxx.spring.domain.Customer#linkmans]
at org.hibernate.internal.util.ReflectHelper.findGetterMethod(ReflectHelper.java:400)
原因:实体类中的名称大小写不一致
四、QueryParameterException:查询参数异常
org.hibernate.QueryParameterException: Position beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based! Position: 2
解决方式:记住Hibernate的SQL—-索引的参数值是从0开始的。
五、GenericJDBCException:通用JDBC异常
org.hibernate.exception.GenericJDBCException: could not execute statement
Caused by: java.sql.SQLException: Field ‘gid’ doesn’t have a default value
原因:外键gid没有默认值,可能在设置主键生成策略没有对应实体类的数据类型
解决方法:如果数据库表中数据类型为Integer,可设置为主键生成策略为increment、native、assign、identity
六、IdentifierGenerationException:标识符产生异常:
org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.xxx.domain.Customer
解决方式:主键id一定需要手动设置(可能在映射文件忘记写主键生成策略)
<!-- 主键生成策略 --> <generator class="native"/>
七、ConstraintViolationException:约束违背异常
org.hibernate.exception.ConstraintViolationException: could not execute statement
造成原因:主键冲突,主键已经存在。
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry ‘2-1’ for key ‘PRIMARY’
解决方法:多对多级联查询,没有释放外键维护权 在对应的映射文件里添加 inverse属性为ture
<set name="linkMans" cascade="save-update,delete" inverse="true"> <!-- 多的一方的外键 --> <key column="lkm_cust_id"/> <!-- 多的一方的类名全路径 --> <one-to-many class="com.xxx.domain.LinkMan"/> </set>
相关文章推荐
- ssh常见开发异常解决办法(转)
- Debug:SSH继承时 could not find a getter for ... in class ... 异常的解决
- [异常解决] windows用SSH和linux同步文件&linux开启SSH&ssh client 报 algorithm negotiation failed的解决方法之一
- spring aop编程与ssh集成的奇怪异常问题解决办法
- ssh整合-[Ljava.lang.String Date类型存入出现异常解决
- ssh 连接异常解决纪实(Shared connection to xxx.xxx.xxx.xxx closed.)
- SSH整合异常解决(creating bean with name 'sessionFactory' defined in class path)
- SSH中懒加载异常的解决办法
- ssh整合系列博客——(2)spring和hibernate整合的异常解决
- [SSH]Not supported by BasicDataSource 异常解决办法
- Linux 因修改/etc/ssh权限导致的ssh不能连接异常解决方法
- SSH的异常解决办法
- ssh整合系列博客——(1)spring和hibernate整合的异常解决
- 因修改/etc/ssh权限导致的ssh不能连接异常解决方法
- Git系列之配置SSH与相关异常解决
- 异常处理:SSH整合中OpenSessionInViewFilter不生效问题的解决
- JSP 开发SSH整合异常解决办法
- ssh整合时报出的异常及解决办法
- 【SSH异常系列】关于SSH中连接数溢出问题的解决方法
- SSH 异常 解决 方案 总结