Hibernate映射文件问题nested exception is org.hibernate.PropertyAccessException:

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Hibernate映射文件问题nested exception is org.hibernate.PropertyAccessException:相关的知识,希望对你有一定的参考价值。

如果有三张表
type [typeNO,typeName],
mytype [typeNO,typeName],
component[componentNO,componentName,type,mytype,standard],

type mytype 的typeNO都是表 component的外键,分别对应的字段是type,mytype

建立Hibernate的映射文件,键生成规则都是native,但是如果想查询type或者是mytype为一个特定值时的数据,那么就抛出

object is not an instance of declaring class
IllegalArgumentException occurred calling getter of com.last.pojo.Mytype.typeNo
IllegalArgumentException occurred calling getter of com.last.pojo.Mytype.typeNo; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.last.pojo.Mytype.typeNo

,请问这是设置了一对多或者set、多对一的影响么?
我映射文件和java基本类都是采用Myeclipse 的ReverseEngineering生成的,所以字段对上的

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="packagesToScan"> <list> <value>com.test.model</value> </list> </property> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.SQLServerDialect hibernate.show_sql=true hibernate.hbm2ddl.auto=update </value> </property> </bean在这段配置中应该加orm 因为异常提示找不到关系映射文件可修改成 <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="mappingResources"> <list> <value>com/test/model/User.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.SQLServerDialect hibernate.show_sql=true hibernate.hbm2ddl.auto=update </value> </property> </bean 参考技术A 你好好看看数据库的字段和映射文件里的字段。。这个是反射抛出的错误

16. nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecogniz

 org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver:handleHttpMessageNotReadable:384 -Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Unrecognized field "auditUnitName" (class com.ylkj.business.auditresult.problem.pojo.dto.ProblemSaveDto), not marked as ignorable (40 known properties: "problemNo", "rectifyperiodEnd", "amountOfPreviousYear", "projectName", "isCarryOver", "institutionProblem", "rectifyperiodStart", "isReportDisclosure", "area", "itemId", "problemNoGw", "requestCompleteTime", "problemAmount", "oneLevelType", "rectifyState", "responsibleUnit", "auditedUnit", "threeLevelType", "checkType", "auditOpinion", "responsiblePerson", "policyBasis", "twoLevelType", "itemTreeLevel", "importance", "currentYearInvolvedAmount", "definitionOfResponsibility", "problemType", "matterId", "year", "isIncludeFormalOpinions", "violationReason", "professionClassify", "isDistribute", "violationNature", "questionDate", "manageReason", "manageUnit", "isRemainProblem", "remainYear"])
 at [Source: java.io.PushbackInputStream@7c1c7412; line: 1, column: 936] (through reference chain: com.ylkj.business.auditresult.problem.pojo.dto.ProblemSaveDto["auditUnitName"]); nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "auditUnitName" (class com.ylkj.business.auditresult.problem.pojo.dto.ProblemSaveDto), not marked as ignorable (40 known properties: "problemNo", "rectifyperiodEnd", "amountOfPreviousYear", "projectName", "isCarryOver", "institutionProblem", "rectifyperiodStart", "isReportDisclosure", "area", "itemId", "problemNoGw", "requestCompleteTime", "problemAmount", "oneLevelType", "rectifyState", "responsibleUnit", "auditedUnit", "threeLevelType", "checkType", "auditOpinion", "responsiblePerson", "policyBasis", "twoLevelType", "itemTreeLevel", "importance", "currentYearInvolvedAmount", "definitionOfResponsibility", "problemType", "matterId", "year", "isIncludeFormalOpinions", "violationReason", "professionClassify", "isDistribute", "violationNature", "questionDate", "manageReason", "manageUnit", "isRemainProblem", "remainYear"])
 at [Source: java.io.PushbackInputStream@7c1c7412; line: 1, column: 936] (through reference chain: com.ylkj.business.auditresult.problem.pojo.dto.ProblemSaveDto["auditUnitName"])

  

解决方案如下:

在需要转化的对象的类中添加注解,注解信息如下:

@JsonIgnoreProperties(ignoreUnknown = true)

以上是关于Hibernate映射文件问题nested exception is org.hibernate.PropertyAccessException:的主要内容,如果未能解决你的问题,请参考以下文章

Hibernate 和 Oracle VARRAYS/嵌套表

16. nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecogniz

在使用hibernate 和spring 构架的框架中如果出现Initialization of bean failed; nested exception is java.lang.NoSuchMe

ssh启动报错:org.dom4j.DocumentException: Connection timed out: connect Nested exception: Connection time

hibernate映射文件问题

hibernate(nested transactions not supported)异常