-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Trying to create a simple many-to-one relationship
PostPosted: Mon Mar 06, 2006 1:51 pm 
Newbie

Joined: Mon Mar 06, 2006 1:17 pm
Posts: 4
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();
}
...
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 06, 2006 2:59 pm 
Beginner
Beginner

Joined: Tue Dec 21, 2004 5:34 pm
Posts: 25
I'm guessing you need a little l long not big l Long.


Top
 Profile  
 
 Post subject: Trying to create a simple many-to-one relationship
PostPosted: Mon Mar 06, 2006 3:54 pm 
Newbie

Joined: Mon Mar 06, 2006 1:17 pm
Posts: 4
Thank you for the quick response.
I switched all references to my id and parentId fields to long instead of Long. Unfortunately, I get the same stack trace.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 07, 2006 4:26 am 
Newbie

Joined: Tue Mar 07, 2006 4:20 am
Posts: 1
I have the same problem. I don't find the solution.

thank you for your replies.


Top
 Profile  
 
 Post subject: Disappointed
PostPosted: Sat Mar 11, 2006 1:27 pm 
Newbie

Joined: Mon Mar 06, 2006 1:17 pm
Posts: 4
Anybody out there? Please help.


Top
 Profile  
 
 Post subject: It's working now.
PostPosted: Sun Mar 12, 2006 7:29 pm 
Newbie

Joined: Mon Mar 06, 2006 1:17 pm
Posts: 4
My problem was a basic lack of understanding of the fact that the many-to-one mapping for the child needed to map to a field in the child class containing an instance of the parent class, not just the key of the parent class. Chapter 21 in the v3 reference cleared it up for me.

http://www.hibernate.org/hib_docs/v3/re ... child.html

Good documentation (if you read it).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.