gpt4 book ai didi

java - Hibernate 错误地在子类而不是父类(super class)中寻找属性的设置者?

转载 作者:行者123 更新时间:2023-12-02 07:52:48 24 4
gpt4 key购买 nike

我有两个类,Event 类和扩展 Event 类的 HazardSubmission 类。

Event有一个属性dateCreated,带有getDateCreated()setDateCreated(String);

当我尝试时:

HazardSubmission hs = new HazardSubmission();
hs.setDateCreated("A");

我假设它会调用 Event 类中的 setter,但它在 HazardSubmission 类中寻找 setter!

这是错误,非常感谢您的帮助! :)

SEVERE: Servlet.service() for servlet DispatcherServlet threw exception
org.hibernate.PropertyNotFoundException: Could not find a setter for property dateCreated in class nz.co.company.healthsafety.stripes.model.HazardSubmission
at org.hibernate.property.BasicPropertyAccessor.createSetter(BasicPropertyAccessor.java:240)
at org.hibernate.property.BasicPropertyAccessor.getSetter(BasicPropertyAccessor.java:233)
at org.hibernate.mapping.Property.getSetter(Property.java:299)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertySetter(PojoEntityTuplizer.java:307)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:142)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:78)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:107)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:135)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:80)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:323)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:456)
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.<init>(JoinedSubclassEntityPersister.java:113)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:87)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:267)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341)
at nz.co.company.healthsafety.stripes.action.BaseController.<clinit>(BaseController.java:36)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at net.sourceforge.stripes.controller.AnnotatedClassActionResolver.makeNewActionBean(AnnotatedClassActionResolver.java:432)
at net.sourceforge.stripes.controller.AnnotatedClassActionResolver.getActionBean(AnnotatedClassActionResolver.java:360)
at net.sourceforge.stripes.controller.NameBasedActionResolver.getActionBean(NameBasedActionResolver.java:264)
at net.sourceforge.stripes.controller.AnnotatedClassActionResolver.getActionBean(AnnotatedClassActionResolver.java:293)
at net.sourceforge.stripes.controller.DispatcherHelper$1.intercept(DispatcherHelper.java:106)
at net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:158)
at net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor.intercept(BeforeAfterMethodInterceptor.java:113)
at net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:155)
at net.sourceforge.stripes.controller.ExecutionContext.wrap(ExecutionContext.java:74)
at net.sourceforge.stripes.controller.DispatcherHelper.resolveActionBean(DispatcherHelper.java:102)
at net.sourceforge.stripes.controller.DispatcherServlet.resolveActionBean(DispatcherServlet.java:238)
at net.sourceforge.stripes.controller.DispatcherServlet.service(DispatcherServlet.java:141)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at net.sourceforge.stripes.controller.StripesFilter.doFilter(StripesFilter.java:247)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
5/04/2012 4:34:42 PM net.sourceforge.stripes.util.Log warn

我的映射 xml 的简化:

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="nz.co.company.healthsafety.stripes.model.Event" table="events">
<id name="id" type="java.lang.Integer" column="id">
<generator class="native" />
</id>
<property name="dateCreated" column="dateCreated" type="timestamp" not-null="true" length="200" />

<joined-subclass name="nz.co.company.healthsafety.stripes.model.HazardSubmission" table="hazard_submissions">
<key column="id" />
<property name="reporterFirstName" column="reporterFirstName" type="java.lang.String" not-null="true" length="200" />
<property name="reporterLastName" column="reporterLastName" type="java.lang.String" not-null="true" length="200" />

</joined-subclass>

</class>
</hibernate-mapping>

最佳答案

根据您的 XML,创建日期应该是时间戳,但您似乎已将该属性声明为字符串。

您可以更改其中一种类型以使它们匹配吗?

关于java - Hibernate 错误地在子类而不是父类(super class)中寻找属性的设置者?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10022816/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com