1.org.hibernate.PropertyAccessException: exception setting property value with
原因:数据库中一些数值字段没有设置为 “允许null”。那么bean中就必须用对象如Integer而不能用int,因为Integer是允许null,int这种数据类型是没有null这种情况的,所以会出错; 解决方法:把数据库中该字段改为not null,xml也要加上 not-null="true"; 2.no session or session was closed 出错环境: 该异常通常是出现在用Load获取信息后,在读取里面数据的时候报的错; 原因:由于Load的时候默认是不去搜索库的,等到你要使用里面的数据时,才去搜索数据库,但这时session已经被你关了; 解决方法:详见《hibernate中lazy的设置》; 3.no session or session was closed 出错环境: 该异常通常是出现在调用bean中级联数据时报的错; BUG原因:由于你搜索主表中数据的时候,Hibernate默认并不去搜索其级联数据(lazy=true时),等你要使用级联数据的时候才去搜索数据库,但这时session已经被你关了; 解决方法:详见《hibernate中lazy的设置》; 4.org.hibernate.exception.GenericJDBCException: could not execute query 出错环境:使用query.setParameter设置中文值时出错,设置字母则搜索正常; BUG原因:由于数据库的驱动包不对; 解决方法:拷贝你连接的库中的jdbc驱动包; 5.org.hibernate.hql.ast.QuerySyntaxException: unexpected token: null 出错环境:使用session.createQuery(hql)的时候出错; BUG原因:由于我的HQL不完整,没有加?号[from Test where username like ?]; 解决方法:把HQL补充完整即可; 6.org.hibernate.exception.GenericJDBCException: Cannot open connection 出错环境:使用session.save()等等这类对库进行操作的语句时出错; BUG原因:Hibernate获取不到数据库连接; 解决方法:查看数据库连接的信息是否正确; 7.org.hibernate.MappingException: Could not read mappings from resource 出错环境:HibernateSessionFactory.rebuildSessionFactory的时候出错 BUG原因:有很多种情况,这边列出我遇到过的 1.hibernate.cfg.xml中配置的XML文件的路径不正确; 2.同一XML在hibernate.cfg.xml写了两次; 解决方法:根据不同情况的解决方法 1. 把错误的XML路径修改过来即可; 2.把重复的XML文件删除掉即可; 8.Hibernate中many-to-one报错ORA-00918: column ambiguously defined 出错环境:当使用setMaxResults和setFirstResult之后再执行查询操作时报错; BUG原因:查看Hibernate执行的HQL会发现里面有搜索出同名字的字段,故而出错; 解决方法:XML中property和many-to-one出现相同的字段,去掉property中该关联字段即可; |
Hibernate错误
最新推荐文章于 2023-12-25 17:50:48 发布