public class Application implements java.io.Serializable {
private long applicationId;
private String policeStation;
private String shortestRoute;
private Set inspectionReports = new HashSet(0);
public Application() {
}
public Application(long applicationId, Applicant applicant) {
this.applicationId = applicationId;
this.applicant = applicant;
}
public Application(long applicationId) {
this.applicationId = applicationId;
}
public Application(long applicationId,String policeStation,String shortestRoute,
Set inspectionReports){
this.applicationId = applicationId;
this.policeStation=policeStation;
this.shortestRoute=shortestRoute;
this.inspectionReports=inspectionReports;
}
public long getApplicationId() {
return this.applicationId;
}
public void setApplicationId(long applicationId) {
this.applicationId = applicationId;
}
public String getPoliceStation() {
return this.policeStation;
}
public void setPoliceStation(String policeStation) {
this.policeStation = policeStation;
}
public String getShortestRoute() {
return this.shortestRoute;
}
public void setShortestRoute(String shortestRoute) {
this.shortestRoute = shortestRoute;
}
public Set getInspectionReports() {
return this.inspectionReports;
}
public void setInspectionReports(Set inspectionReports) {
this.inspectionReports = inspectionReports;
}
}
相应的HBM是
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 18 Jun, 2012 3:04:42 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="nic.mams.model.Application" schema="public" table="application">
<id name="applicationId" type="long">
<column name="application_id"/><generator class="increment"/>
</id>
<property generated="never" lazy="false" name="policeStation" type="string"><column name="police_station"/></property>
<property generated="never" lazy="false" name="shortestRoute" type="string"><column name="shortest_route"/></property>
<set cascade="all,delete-orphan" fetch="select" inverse="true" lazy="true" name="inspectionReports" sort="unsorted" table="inspection_report">
<key><column name="application_id"/></key>
<one-to-many class="nic.mams.model.InspectionReport"/>
</set>
</class>
</hibernate-mapping>
InspectionReport类是
public class InspectionReport implements java.io.Serializable {
private long inspectionReportId;
private Application application;
private Date inspectedOn;
public InspectionReport() {
}
public InspectionReport(long inspectionReportId,Application application) {
this.inspectionReportId = inspectionReportId;
this.application = application;
}
public InspectionReport(long inspectionReportId) {
this.inspectionReportId = inspectionReportId;
}
public InspectionReport(long inspectionReportId,Application application,Date inspectedOn) {
this.inspectionReportId = inspectionReportId;
this.application = application;
this.inspectedOn = inspectedOn;
}
public long getInspectionReportId() {
return this.inspectionReportId;
}
public void setInspectionReportId(long inspectionReportId) {
this.inspectionReportId = inspectionReportId;
}
public Application getApplication() {
return this.application;
}
public void setApplication(Application application) {
this.application = application;
}
public Date getInspectedOn() {
return this.inspectedOn;
}
public void setInspectedOn(Date inspectedOn) {
this.inspectedOn = inspectedOn;
}
}
相应的HBM是
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 14 Nov, 2011 5:11:45 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="nic.mams.model.InspectionReport" table="inspection_report" schema="public">
<id name="inspectionReportId" type="long">
<column name="inspection_report_id" />
<generator class="increment"/>
</id>
<many-to-one name="application" class="nic.mams.model.Application" fetch="select">
<column name="application_id" />
</many-to-one>
<property name="inspectedOn" type="date">
<column name="inspected_on" length="13" />
</property>
</class>
</hibernate-mapping>
当我执行下面的代码时,我得到了一个例外 Application application = new Application(); ................................. saveOrUpdate(应用程序);
例外是
2013-11-15 10:50:01,346 ERROR [org.hibernate.property.BasicPropertyAccessor] (http-10.162.9.129-8080-3) IllegalArgumentException in class: nic.mams.model.InspectionReport, getter method of property: inspectionReportId
2013-11-15 10:50:01,347 ERROR [STDERR] (http-10.162.9.129-8080-3) org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.hibernate3.HibernateSystemException: IllegalArgumentException occurred calling getter of nic.mams.model.InspectionReport.inspectionReportId; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of nic.mams.model.InspectionReport.inspectionReportId
2013-11-15 10:50:01,347 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:488)
2013-11-15 10:50:01,349 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:441)
2013-11-15 10:50:01,349 ERROR [STDERR] (http-10.162.9.129-8080-3) at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
2013-11-15 10:50:01,349 ERROR [STDERR] (http-10.162.9.129-8080-3) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
2013-11-15 10:50:01,349 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324)
2013-11-15 10:50:01,349 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242)
2013-11-15 10:50:01,349 ERROR [STDERR] (http-10.162.9.129-8080-3) at nic.mams.web.SessionFilter.doFilter(SessionFilter.java:46)
2013-11-15 10:50:01,350 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274)
2013-11-15 10:50:01,350 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242)
2013-11-15 10:50:01,350 ERROR [STDERR] (http-10.162.9.129-8080-3) at nic.mams.jstl.tag.FilterConfig.doFilter(FilterConfig.java:33)
2013-11-15 10:50:01,350 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274)
2013-11-15 10:50:01,350 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242)
2013-11-15 10:50:01,351 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
2013-11-15 10:50:01,351 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
2013-11-15 10:50:01,351 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181)
2013-11-15 10:50:01,351 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285)
2013-11-15 10:50:01,351 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261)
2013-11-15 10:50:01,351 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88)
2013-11-15 10:50:01,351 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100)
2013-11-15 10:50:01,351 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
2013-11-15 10:50:01,351 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
2013-11-15 10:50:01,351 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
2013-11-15 10:50:01,351 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
2013-11-15 10:50:01,351 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53)
2013-11-15 10:50:01,351 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362)
2013-11-15 10:50:01,351 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
2013-11-15 10:50:01,352 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654)
2013-11-15 10:50:01,352 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951)
2013-11-15 10:50:01,352 ERROR [STDERR] (http-10.162.9.129-8080-3) at java.lang.Thread.run(Unknown Source)
2013-11-15 10:50:01,352 ERROR [STDERR] (http-10.162.9.129-8080-3) Caused by: org.springframework.orm.hibernate3.HibernateSystemException: IllegalArgumentException occurred calling getter of nic.mams.model.InspectionReport.inspectionReportId; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of nic.mams.model.InspectionReport.inspectionReportId
2013-11-15 10:50:01,353 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:659)
2013-11-15 10:50:01,353 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
2013-11-15 10:50:01,353 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:378)
2013-11-15 10:50:01,353 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.springframework.orm.hibernate3.HibernateTemplate.merge(HibernateTemplate.java:769)
2013-11-15 10:50:01,353 ERROR [STDERR] (http-10.162.9.129-8080-3) at nic.mams.hibernate.QPQLMLInspec2Hibernate.saveOrUpdateInspec(QPQLMLInspec2Hibernate.java:2035)
2013-11-15 10:50:01,353 ERROR [STDERR] (http-10.162.9.129-8080-3) at nic.mams.serviceimpl.QPQLMLInspec2serviceImpl.saveOrUpdateInspec(QPQLMLInspec2serviceImpl.java:338)
2013-11-15 10:50:01,353 ERROR [STDERR] (http-10.162.9.129-8080-3) at nic.mams.web.QPQLMLFirstInspecController.processFinish(QPQLMLFirstInspecController.java:1211)
2013-11-15 10:50:01,353 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.springframework.web.servlet.mvc.AbstractWizardFormController.validatePagesAndFinish(AbstractWizardFormController.java:656)
2013-11-15 10:50:01,353 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.springframework.web.servlet.mvc.AbstractWizardFormController.processFormSubmission(AbstractWizardFormController.java:493)
2013-11-15 10:50:01,353 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:265)
2013-11-15 10:50:01,353 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
2013-11-15 10:50:01,353 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
2013-11-15 10:50:01,353 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:861)
2013-11-15 10:50:01,353 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:795)
2013-11-15 10:50:01,353 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
2013-11-15 10:50:01,354 ERROR [STDERR] (http-10.162.9.129-8080-3) ... 28 more
2013-11-15 10:50:01,354 ERROR [STDERR] (http-10.162.9.129-8080-3) Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of nic.mams.model.InspectionReport.inspectionReportId
2013-11-15 10:50:01,354 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:195)
2013-11-15 10:50:01,354 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:206)
2013-11-15 10:50:01,354 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3619)
2013-11-15 10:50:01,354 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:145)
2013-11-15 10:50:01,354 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:714)
2013-11-15 10:50:01,354 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:696)
2013-11-15 10:50:01,354 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.engine.CascadingAction$6.cascade(CascadingAction.java:268)
2013-11-15 10:50:01,354 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:291)
2013-11-15 10:50:01,355 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:239)
2013-11-15 10:50:01,355 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:192)
2013-11-15 10:50:01,355 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:319)
2013-11-15 10:50:01,355 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:265)
2013-11-15 10:50:01,355 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:242)
2013-11-15 10:50:01,355 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:192)
2013-11-15 10:50:01,355 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.engine.Cascade.cascade(Cascade.java:153)
2013-11-15 10:50:01,355 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.event.def.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:459)
2013-11-15 10:50:01,355 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:318)
2013-11-15 10:50:01,355 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:167)
2013-11-15 10:50:01,355 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:81)
2013-11-15 10:50:01,356 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:704)
2013-11-15 10:50:01,356 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:688)
2013-11-15 10:50:01,356 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:692)
2013-11-15 10:50:01,356 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.springframework.orm.hibernate3.HibernateTemplate$23.doInHibernate(HibernateTemplate.java:772)
2013-11-15 10:50:01,356 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:373)
2013-11-15 10:50:01,356 ERROR [STDERR] (http-10.162.9.129-8080-3) ... 40 more
2013-11-15 10:50:01,357 ERROR [STDERR] (http-10.162.9.129-8080-3) Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
2013-11-15 10:50:01,357 ERROR [STDERR] (http-10.162.9.129-8080-3) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2013-11-15 10:50:01,357 ERROR [STDERR] (http-10.162.9.129-8080-3) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
2013-11-15 10:50:01,357 ERROR [STDERR] (http-10.162.9.129-8080-3) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
2013-11-15 10:50:01,358 ERROR [STDERR] (http-10.162.9.129-8080-3) at java.lang.reflect.Method.invoke(Unknown Source)
2013-11-15 10:50:01,358 ERROR [STDERR] (http-10.162.9.129-8080-3) at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:169)
答案 0 :(得分:0)
也许applicationId的值为null。因为原始long不能处理null,所以如果它是null,则会抛出错误。尝试将类型更改为Long,这是long的对象实现。