关于 org.hibernate.WrongClassException 错误的解决!
首先看log(中间的null有可能是数字),说明在保存时出现子类id不匹配的问题。
Object with id: null was not of the specified subclass: org.appfuse.model.User (class of the given object did not match class of persistent copy);
nested exception is org.hibernate.WrongClassException: Object with id: null was not of the specified subclass: org.appfuse.model.User (class of the given object did not match class of persistent copy)
问题很奇怪,同样的代码在以往是有效的。由于本人比较懒于是乎就查了google,发现是与子类映射有关?
详细描述大家可以参考网络上面的,这里我只说解决方法。
简单讲,问题时出现在与子类相关的映射中:
比如 User 实体有两个子类 Employee,Employer(举例),
我们直接修改 user 并保存于是出现了上面的异常,但同样的代码却可以保存 Employee和Employer实体,原因是hibernate不能确定其中一个这个实体子类。于是将原来的代码加上:
BeanUtils.copyProperties(user, employee);
直接copy一个Employee实体出来以确定使用哪个子类,于是乎现在保存就行了。
原则上就是:既然hibernate无法确认子类那我们就帮帮他确认好了。
原因不分析了,这不是俺的强项。呵呵~~
另外,如果哪位大侠有高见麻烦留个言吧,以便在下可以学习一下。多有谢过啦~~~!
还有就是如果页面中出现了重复的域也有可能导致问题,这个需要仔细检查页面。
分享到:
相关推荐
weblogic12 下最新 org.hibernate.hql.ast.HqlToken解决办法
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/...
No Hibernate Session bound to thread,没有绑定线程解决办法,找了好久才找到的
org.hibernate.jpa.QueryHints jar hibernate-entitymanager-4.3.0.Final.jar
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider] at org.hibernate.service.internal....
Class'org.springframework.orm.hibernate3.LocalSessionFactoryBean'not found 解决办法
NULL 博文链接:https://hw1287789687.iteye.com/blog/1967701
org.hibernate.eclipse.feature_3.2.3.GAorg.hibernate.eclipse.feature_3.2.3.GA
在eclipse上通过hibernate...重启eclipse即可生效(插件包所在路径是:D:\eclipse\plugins\org.hibernate.eclipse.libs_3.6.0.Final-v20130327-1513-B111\lib\tools\hibernate-tools-3.4.0.CR2.jar(版本号可能有出入))
jar包,官方版本,自测可用
NULL 博文链接:https://hw1287789687.iteye.com/blog/1947557
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory 3.3配置如下: <property name="hibernate.cache.use_second_level_cache">true <property name="cache...
osgi下web开发hibernate库,可以在virgo jetty上使用。
osgi开发中的hibernate库,可以从springsource上下载。适用于virgo服务器。
Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.connection.C3P0ConnectionProvider] as strategy [org.hibernate.engine.jdbc.... ...
包含hibernate所有所需jar包还有一些其他包日志包、jpa支持包等: 列如:hibernate-core-5.1.0.Final.jar hibernate-ehcache-5.1.0.Final.jar hibernate-entitymanager-5.1.0.Final.jar hibernate-envers-5.1.0....
weblogic10 与hibernate冲突解决方案 错误如下:org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken linux windows 环境解决方案全解 Linux 启动脚本添加如下: export USER_...
hibernate简单的demo,编程语言——Java,框架——Spring,框架——Hibernate
org.hibernate.TransactionException: JDBC rollback failed
org.hibernate.cfg This package defines APIs for configuring Hibernate, and classes for building the Hibernate configuration-time metamodel. org.hibernate.classic This package implements backward-...