I'm trying to create a simple many-to-one relationship and am getting the stack trace shown below after my comments.
Environment:
MyEclipse 4.1.0GA.
Hibernate 3.0.5 (ships with MyEclipse)
JRE 1.5.0_02
JBoss 4.0.2RC1
MySQL 5.0.18
All is on a development machine running Windows XP SP2.
I've conclude the mapping file, the code snippet that's trying to
save the objects, and code snippets from the BaseBO, SalesPersonBO, and EditHistory classes.
The BaseBO class contains a Long id (primary key) field and the appropriate getter and setter methods.
The SalesPersonBO class extends the BaseBO class.
The EditHistory class contains a Long id (primary key) field and a Long parentId (foreign key) field, both of
which contain the appropriate getters and setters.
Any help would be greatly appreciated.
The stack trace:
11:26:34,831 ERROR [BasicPropertyAccessor] IllegalArgumentException in class: com.enpesna.base.BaseBO, getter method of property: id
11:26:34,861 INFO [STDOUT] com.enpesna.ApplicationException: An internal error occurred saving sales person John Doe, ID #13
11:26:34,861 INFO [STDOUT] at com.enpesna.businessobjects.it.sampleapp.BusinessDelegateImpl.saveSalesPerson(BusinessDelegateImpl.java:138)
11:26:34,861 INFO [STDOUT] at com.enpesna.it.sampleapp.struts.UpdateSalesPersonAction.storeSalesPerson(UpdateSalesPersonAction.java:121)
11:26:34,861 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
11:26:34,861 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
11:26:34,861 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
11:26:34,861 INFO [STDOUT] at java.lang.reflect.Method.invoke(Method.java:585)
11:26:34,861 INFO [STDOUT] at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:274)
11:26:34,861 INFO [STDOUT] at org.apache.struts.actions.LookupDispatchAction.execute(LookupDispatchAction.java:160)
11:26:34,861 INFO [STDOUT] at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
11:26:34,861 INFO [STDOUT] at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
11:26:34,861 INFO [STDOUT] at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
11:26:34,861 INFO [STDOUT] at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
11:26:34,861 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
11:26:34,861 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
11:26:34,861 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
11:26:34,861 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
11:26:34,861 INFO [STDOUT] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
11:26:34,861 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
11:26:34,861 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
11:26:34,861 INFO [STDOUT] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
11:26:34,861 INFO [STDOUT] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
11:26:34,861 INFO [STDOUT] at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
11:26:34,861 INFO [STDOUT] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:147)
11:26:34,861 INFO [STDOUT] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:53)
11:26:34,861 INFO [STDOUT] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
11:26:34,861 INFO [STDOUT] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
11:26:34,861 INFO [STDOUT] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
11:26:34,861 INFO [STDOUT] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
11:26:34,861 INFO [STDOUT] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
11:26:34,861 INFO [STDOUT] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:743)
11:26:34,861 INFO [STDOUT] at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
11:26:34,871 INFO [STDOUT] at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
11:26:34,871 INFO [STDOUT] at java.lang.Thread.run(Thread.java:595)
11:26:34,871 INFO [STDOUT] Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.enpesna.base.BaseBO.id
11:26:34,871 INFO [STDOUT] at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:119)
11:26:34,871 INFO [STDOUT] at org.hibernate.tuple.AbstractTuplizer.getIdentifier(AbstractTuplizer.java:103)
11:26:34,871 INFO [STDOUT] at org.hibernate.persister.entity.BasicEntityPersister.getIdentifier(BasicEntityPersister.java:2944)
11:26:34,871 INFO [STDOUT] at org.hibernate.persister.entity.BasicEntityPersister.isTransient(BasicEntityPersister.java:2705)
11:26:34,871 INFO [STDOUT] at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:181)
11:26:34,871 INFO [STDOUT] at org.hibernate.engine.ForeignKeys$Nullifier.isNullifiable(ForeignKeys.java:137)
11:26:34,871 INFO [STDOUT] at org.hibernate.engine.ForeignKeys$Nullifier.nullifyTransientReferences(ForeignKeys.java:69)
11:26:34,871 INFO [STDOUT] at org.hibernate.engine.ForeignKeys$Nullifier.nullifyTransientReferences(ForeignKeys.java:47)
11:26:34,871 INFO [STDOUT] at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:234)
11:26:34,871 INFO [STDOUT] at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:160)
11:26:34,871 INFO [STDOUT] at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:95)
11:26:34,871 INFO [STDOUT] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
11:26:34,871 INFO [STDOUT] at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
11:26:34,871 INFO [STDOUT] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
11:26:34,871 INFO [STDOUT] at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
11:26:34,871 INFO [STDOUT] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
11:26:34,871 INFO [STDOUT] at org.hibernate.impl.SessionImpl.save(SessionImpl.java:481)
11:26:34,871 INFO [STDOUT] at org.hibernate.impl.SessionImpl.save(SessionImpl.java:476)
11:26:34,871 INFO [STDOUT] at com.enpesna.businessobjects.it.sampleapp.BusinessDelegateImpl.saveSalesPerson(BusinessDelegateImpl.java:120)
11:26:34,871 INFO [STDOUT] ... 32 more
11:26:34,871 INFO [STDOUT] Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
11:26:34,871 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
11:26:34,871 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
11:26:34,871 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
11:26:34,871 INFO [STDOUT] at java.lang.reflect.Method.invoke(Method.java:585)
11:26:34,871 INFO [STDOUT] at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:105)
11:26:34,871 INFO [STDOUT] ... 50 more
The mapping file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class name="com.enpesna.businessobjects.it.sampleapp.SalesPersonBO" table="SALES_PERSON_TBL">
<id name="id" type="long" column="ID">
<generator class="native" />
</id>
<property name="createDate" type="timestamp" column="CREATE_DATE" not-null="false" />
<property name="createdBy" type="string" column="CREATED_BY" not-null="false" />
<property name="name" type="string" column="NAME" not-null="true" unique="true" />
<property name="territory" type="string" column="TERRITORY" />
<property name="commissionRate" type="double" column="COMMISSION_RATE" />
</class>
<class name="com.enpesna.EditHistory" table="EDIT_HISTORY_TBL">
<id name="id" type="long" column="ID">
<generator class="native" />
</id>
<property name="editDate" type="timestamp" column="EDIT_DATE" not-null="true" />
<property name="editBy" type="string" column="EDIT_BY" not-null="true" />
<property name="comment" type="string" column="COMMENT" not-null="false" />
<many-to-one name="parentId" class="com.enpesna.businessobjects.it.sampleapp.SalesPersonBO" column="FK_PARENT_ID" />
</class>
</hibernate-mapping>
Here's the Java code that's trying to save the objects.
...
hibernateSession = HibernateSessionFactory.currentSession(username, password);
transaction = hibernateSession.beginTransaction();
if (id == null) {
returnedId = hibernateSession.save(salesPersonBO);
} else {
hibernateSession.update(salesPersonBO, id);
returnedId = id;
}
// This constructor or EditHistory sets the foreign key corresponding to the primary key
// in the salesPersonBO object and one data field.
EditHistory history = new EditHistory((Long) returnedId, editor);
hibernateSession.save(history);
transaction.commit();
...
Here's the Java code for the BaseBO class.
public abstract class BaseBO implements Serializable {
private Long id; // A unique identifier for the object.
...
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
...
}
Here's the Java code for the SalesPersonBO class.
public class SalesPersonBO extends BaseBO {
private String name;
private String territory;
private double commissionRate;
public SalesPersonBO() {
super();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTerritory() {
return territory;
}
public void setTerritory(String territory) {
this.territory = territory;
}
public double getCommissionRate() {
return commissionRate;
}
public void setCommissionRate(double commissionRate) {
this.commissionRate = commissionRate;
}
}
Here's the Java code for the EditHistory class.
public class EditHistory implements Serializable {
private Long id;
private Long parentId;
private String editBy;
private Date editDate;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getParentId() {
return parentId;
}
public void setParentId(Long parentId) {
this.parentId = parentId;
}
public String getEditBy() {
return editBy;
}
public void setEditBy(String editBy) {
this.editBy = editBy;
}
public Date getEditDate() {
return editDate;
}
public void setEditDate(Date editDate) {
this.editDate = editDate;
}
public EditHistory(Long parentId, String editBy) {
this.parentId = parentId;
this.editBy = editBy;
this.editDate = new Date();
}
...
}
|