-->
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.  [ 7 posts ] 
Author Message
 Post subject: IllegalArgumentException -- getter method of property
PostPosted: Fri Apr 28, 2006 2:16 pm 
Newbie

Joined: Fri Apr 07, 2006 6:04 pm
Posts: 12
The question is at the bottom of all this.


Hibernate version: 3.1

Mapping documents:

Code:
<?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="Activities">
      <id name="farblatz" column="ACTIVITYGROUP_ID">
         <generator class="native"/>
      </id>
   
      <list name="Steps" cascade="all-delete-orphan">
            <key column="ACTIVITYGROUP_ID" not-null="true"/>
            <list-index column="stepIndex"/>
            <one-to-many class="ActivityStep" />
        </list>
      
      <property name="xxx" not-null="false"/>
      
   </class>

</hibernate-mapping>


Code:
<?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="ActivityStep" lazy="true">
      <id name="stepID">
         <generator class="native"/>
      </id>
      <discriminator column="classID"/>
      
      <many-to-one
         name="stepOwner"
         class="Activities"
         column="ACTIVITYGROUP_ID"
         not-null="true"
         insert="false"
         update="false"
      />
      <property name="Comment" not-null="false"/>
      
   </class>
   
</hibernate-mapping>



Full stack trace of any exception that occurs:

Code:
INFO  - Hibernate 3.1.2
INFO  - hibernate.properties not found
INFO  - using CGLIB reflection optimizer
INFO  - using JDK 1.4 java.sql.Timestamp handling
INFO  - configuring from file: hibernate.cfg.xml
INFO  - Reading mappings from resource: Act1.hbm.xml
INFO  - Mapping class: ActivityStep -> ActivityStep
INFO  - Reading mappings from resource: Act.hbm.xml
INFO  - Mapping class: Activities -> Activities
INFO  - Configured SessionFactory: null
INFO  - Mapping collection: Activities.Steps -> ActivityStep
INFO  - Using Hibernate built-in connection pool (not for production use!)
INFO  - Hibernate connection pool size: 20
INFO  - autocommit mode: false
INFO  - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://mymachine/test_hibernate
INFO  - connection properties: {user=userid}
INFO  - RDBMS: MySQL, version: 5.0.15-nt
INFO  - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.12 ( $Date: 2005-11-17 15:53:48 +0100 (Thu, 17 Nov 2005) $, $Revision$ )
INFO  - Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
INFO  - Using default transaction strategy (direct JDBC transactions)
INFO  - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
INFO  - Automatic flush during beforeCompletion(): disabled
INFO  - Automatic session close at end of transaction: disabled
INFO  - JDBC batch size: 15
INFO  - JDBC batch updates for versioned data: disabled
INFO  - Scrollable result sets: enabled
INFO  - JDBC3 getGeneratedKeys(): enabled
INFO  - Connection release mode: auto
INFO  - Maximum outer join fetch depth: 2
INFO  - Default batch fetch size: 1
INFO  - Generate SQL with comments: enabled
INFO  - Order SQL updates by primary key: disabled
INFO  - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
INFO  - Using ASTQueryTranslatorFactory
INFO  - Query language substitutions: {}
INFO  - Second-level cache: enabled
INFO  - Query cache: disabled
INFO  - Cache provider: org.hibernate.cache.EhCacheProvider
INFO  - Optimize cache for minimal puts: disabled
INFO  - Structured second-level cache entries: disabled
INFO  - Echoing all SQL to stdout
INFO  - Statistics: disabled
INFO  - Deleted entity synthetic identifier rollback: disabled
INFO  - Default entity-mode: pojo
INFO  - building session factory
WARN  - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/hibernate-3.1/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
INFO  - Not binding factory to JNDI, no JNDI name configured
INFO  - Running hbm2ddl schema export
INFO  - exporting generated schema to database
INFO  - schema export complete
Hibernate:
    /* insert Activities
        */ insert
        into
            Activities
            (xxx)
        values
            (?)
ERROR - IllegalArgumentException in class: Activities, getter method of property: farblatz
Exception in thread "main" org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of Activities.farblatz
   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$Nullifier.isNullifiable(ForeignKeys.java:137)
   at org.hibernate.engine.ForeignKeys$Nullifier.nullifyTransientReferences(ForeignKeys.java:69)
   at org.hibernate.engine.ForeignKeys$Nullifier.nullifyTransientReferences(ForeignKeys.java:47)
   at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:263)
   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:101)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:98)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
   at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:531)
   at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:523)
   at org.hibernate.engine.CascadingAction$1.cascade(CascadingAction.java:134)
   at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:213)
   at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:157)
   at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
   at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:290)
   at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:185)
   at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:160)
   at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
   at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
   at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:410)
   at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:299)
   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:101)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
   at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
   at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
   at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:559)
   at org.hibernate.impl.SessionImpl.save(SessionImpl.java:547)
   at org.hibernate.impl.SessionImpl.save(SessionImpl.java:543)
   at Test.<init>(Test.java:84)
   at Test.main(Test.java:106)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
   ... 39 more



Name and version of the database you are using: MySQL v5.x


Class files

Code:
import java.util.List;
import java.util.Set;

public class Activities {
   int            farblatz;

   

   List         Steps               = null;

   int            xxx;

   public Activities() {
      super();
   }

   
   /**
    * @return the steps
    */
   public List getSteps() {
      return Steps;
   }

   /**
    * @param steps the steps to set
    */
   public void setSteps(List steps) {
      Steps = steps;
   }

   public int getFarblatz() {
      return farblatz;
   }

   /**
    * @param farblatz the farblatz to set
    */
   public void setFarblatz(int farblatz) {
      this.farblatz = farblatz;
   }

   /**
    * @return the xxx
    */
   public int getXxx() {
      return xxx;
   }

   /**
    * @param xxx the xxx to set
    */
   public void setXxx(int xxx) {
      this.xxx = xxx;
   }

}


Code:
public class ActivityStep {
   int            stepOwner         = 0;
   int            stepID            = 0;

String comment=null;
   

   public ActivityStep() {}

   
   /**
    * @return Returns the comment.
    */
   public String getComment() {
      return Comment;
   }

   /**
    * @param comment The comment to set.
    */
   public void setComment(String comment) {
      Comment = comment;
   }

   
   /**
    * @return Returns the stepID.
    */
   public int getStepID() {
      return stepID;
   }

   /**
    * @param stepID The stepID to set.
    */
   public void setStepID(int stepID) {
      this.stepID = stepID;
   }

   /**
    * @return the stepOwner
    */
   public int getStepOwner() {
      return stepOwner;
   }

   /**
    * @param stepOwner the stepOwner to set
    */
   public void setStepOwner(int stepOwner) {
      this.stepOwner = stepOwner;
   }

}



The problem:

The definition above when run appears to be telling me that the getter for farblatz does not exists, yet it clearly does in the code. I followed this code in the debugger until it got an IllegalArgumentException. The error is from reflection saying that it can't make a getFarblatz call on the object provided. The object provided is an Integer not an Activities which is why the exception is raised.

If I watch access to getFarblatz, there is a call made by hibernate to get it's value but it seems like instead of stopping there, it then tries to use the result, an Integer, as an activities object. This is the direct source of the error.

My question is whether I've specified the mapping incorrectly or is this a bug in hibernate. Aren't list of objects a common thing?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 2:30 pm 
Regular
Regular

Joined: Wed Feb 22, 2006 11:28 am
Posts: 65
Location: Santiago, Chile
clean ur project all *.class, and rebuild ur project. Is very possible that: your IDE donĀ“t refresh with la last version of that Class.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 2:36 pm 
Newbie

Joined: Fri Apr 07, 2006 6:04 pm
Posts: 12
I've done that many times. it makes no difference.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 2:46 pm 
Regular
Regular

Joined: Wed Feb 22, 2006 11:28 am
Posts: 65
Location: Santiago, Chile
[quote="awax"]I've done that many times. it makes no difference.[/quote]

Change your "farblatz" type to long, and in your hibernate mapping, add type="long"


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 29, 2006 2:04 pm 
Newbie

Joined: Fri Apr 07, 2006 6:04 pm
Posts: 12
I'll give that a try. More on Monday. Thanks you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 11:05 am 
Newbie

Joined: Fri Apr 07, 2006 6:04 pm
Posts: 12
Changing to long made no difference.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 3:31 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
In your ActivityStep class you have declared 'stepOwner' as type int. Instead declare it as Activities class type, because in the mapping file you specified the class attribute.


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