-->
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.  [ 4 posts ] 
Author Message
 Post subject: IllegalArgumentException occurred calling getter
PostPosted: Thu Mar 30, 2006 8:40 am 
Newbie

Joined: Thu Mar 30, 2006 7:53 am
Posts: 3
Hibernate version: 3.1.2

Database:
MySQL

Using tomcat 5.5


I've got a mapping of a bag which contains objects which also contain a bag of objects.
The mapping of the top parent class looks like this:

<class name="WasteProcess" table="WASTE_PROCESS"
dynamic-insert="true"
dynamic-update="true">

<id name="id" type="string" unsaved-value="null" >
<column name="WASTE_PROCESS_ID" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>

<property name="ProcessDescription">
<column name="PROCESS_DESCRIPTION" length="250" not-null="false"/>
</property>


<many-to-one column="SIC_ID" name="sic"
class="SicCode" not-null="false"/>


<bag name="streams" table="waste_stream_link"
>
<key column="waste_process_id"/>
<many-to-many class="WasteStream"
column="waste_stream_id"/>
</bag>

</class>

Where WasteStream contains a bag of another obect.

Inserting objects into the WasteStream collection works fine so I know my mappings arent totally off base.
But when I come to insert instances into WasteProcess in the same way it fails on insertion of data into the link table. The error looks like this:


Hibernate:
insert
into
waste_stream_link
(waste_process_id, waste_stream_id)
values
(?, ?)
13:11:59,093 DEBUG AbstractBatcher:424 - preparing statement
13:11:59,093 ERROR BasicPropertyAccessor:167 - IllegalArgumentException in class: uk.co.wasteroute.BaseEntity, getter method of property: id
13:11:59,109 ERROR AbstractFlushingEventListener:299 - Could not synchronize database state with session
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of uk.co.wasteroute.BaseEntity.id
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
at org.hibernate.tuple.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:176)
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3257)
at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:2983)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:181)
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:215)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:108)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:71)
at org.hibernate.persister.collection.AbstractCollectionPersister.writeElement(AbstractCollectionPersister.java:697)
at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1037)
at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:26)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:144)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1009)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:356)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at uk.co.wasteroute.HibernateUtil.commitTransaction(HibernateUtil.java:116)
at uk.co.wasteroute.WasteProcessDAO.createWasteProcess(WasteProcessDAO.java:42)
at uk.co.wasteroute.createConsignmentNote.doPost(createConsignmentNote.java:33)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:667)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: java.lang.ClassCastException@1df2964
at sun.reflect.GeneratedMethodAccessor52.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
... 37 more

Both the WasteProcess class and the WasteStream class do indeed inhert from BaseEntity which is a class used to hold the id attribute and the associated setter and getter.
But removing this inheritance and putting the attribute in the WasteStream and WasteProcess class doesn't help. I still get the same error.

I'm new to hibernate but was getting on well with it until this I'm sure I'm doing something silly. If anyone has any ideas I would be grateful.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 9:29 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The base exception is a ClassCastException in BaseEntity.getId(). Is there anything in that code more complex than "return id;"? Is id not a String? What are the various mappings that you've left out: WasteStream and whatever class its bag contains? Do they all have the same type (String) for their id?

Another possibility for this kind of exception is that you've specified a class as the key in a mapping (via component-id + key-many-to-one, probably), but you're providing the id of an object in java code, when you should be providing the object itself.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 31, 2006 4:51 am 
Newbie

Joined: Thu Mar 30, 2006 7:53 am
Posts: 3
All objects inheret their id attribute from BaseEntity and so all have the same method. GetId() is indeed just return id; which is indeed a String.

Your second suggestion had occured to me. I'm pretty sure I am providing the objects themselves but I'll have another look.

Thanks for taking an interest I'll try and provide more information in another post.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 05, 2006 11:53 am 
Newbie

Joined: Thu Mar 30, 2006 7:53 am
Posts: 3
tenwit wrote:
The base exception is a ClassCastException in BaseEntity.getId(). Is there anything in that code more complex than "return id;"? Is id not a String? What are the various mappings that you've left out: WasteStream and whatever class its bag contains? Do they all have the same type (String) for their id?

Another possibility for this kind of exception is that you've specified a class as the key in a mapping (via component-id + key-many-to-one, probably), but you're providing the id of an object in java code, when you should be providing the object itself.



You know what you were absolutely correct with your second guess. I'd missed it the first time round but there it is.
Thanks for the help.

Case closed


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.