-->
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 - getter method of property: id
PostPosted: Tue Apr 06, 2010 8:59 am 
Regular
Regular

Joined: Wed Mar 10, 2010 4:48 am
Posts: 106
I'm making an application which uses multiple languages.
For this example I have the classes Country, Language and CountryName. CountryName has Foreign Keys to Country and Language.
For example: CountryName could contain: England, Engeland, Angleterre, Inglaterra.

I get the error below, which I can't solve.
Code:
ERROR - (BasicPropertyAccessor.java:191) - IllegalArgumentException in class: data.Country, getter method of property: id
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of data.Country.id
   at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:195)
   at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:206)
   at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3619)
   at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3335)
   at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:204)
   at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:241)
   at org.hibernate.type.EntityType.getIdentifier(EntityType.java:430)
   at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:110)
   at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1728)
   at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1699)
   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1589)
   at org.hibernate.loader.Loader.doQuery(Loader.java:696)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
   at org.hibernate.loader.Loader.doList(Loader.java:2228)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
   at org.hibernate.loader.Loader.list(Loader.java:2120)
   at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1596)
   at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
   at main.HibernateMain.main(HibernateMain.java:27)
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:597)
   at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:169)
   ... 19 more

These are the mappings:
Code:
   <class name="data.Country" table="countries">
      <id name="id" column="id" length="31">
         <generator class="assigned" />
      </id>

      <set name="countryNames" table="countryNames" inverse="true" cascade="delete">
         <key column="country" />
         <one-to-many class="data.CountryName" />
      </set>
   </class>
Code:
   <class name="data.Language" table="languages">
      <id name="id" column="id" length="31">
         <generator class="assigned" />
      </id>

      <set name="countryNames" table="countryNames" inverse="true" cascade="delete">
         <key column="language" />
         <one-to-many class="data.CountryName" />
      </set>
   </class>
Note: The id is used as a workaround. Country and Language should work as a composite key, but I can't get the composite-id working.
Code:
   <class name="data.CountryName" table="countryNames">
      <id name="id" column="id" length="31">
         <generator class="assigned" />
      </id>

      <properties name="countryLanguageUnique" unique="true">
         <many-to-one name="country" class="data.Country" column="country" not-null="true" />
         <many-to-one name="language" class="data.Language" column="language" not-null="true" />
      </properties>
      <property name="name" column="name" />
   </class>

And this is the class the error is complaining about:
Code:
public class Country
{
   private String id;
   private Set<CountryName> countryNames = new HashSet<CountryName>(0);
   ...
   
   /* Getters */
   public String getId()
   {
      return id;
   }
   
   public Set<CountryName> getCountryNames()
   {
      return countryNames;
   }
   
   /* Setters */
   private void setId(String id)
   {
      this.id = id;
   }
   
   public void setCountryNames(Set<CountryName> countryNames)
   {
      this.countryNames = countryNames;
   }
}

I'm using this test code:
Code:
   public static void main(String[] args)
   {
      Session session = SessionHandler.getSession();
      Criteria crit = session.createCriteria(CountryName.class)
            .add(Restrictions.eq("country", "Auke-yyyy-DDD-kk-mm-ss-SSS-0001"))
            .add(Restrictions.eq("language", "Auke-yyyy-DDD-kk-mm-ss-SSS-0001"));
      Logger.get().trace("Testing: 1");
      List<CountryName> list = crit.list();
      Logger.get().trace("Testing: 2");
      System.out.println(list.get(0).getName());
   }
}

The error occurs at: "List<CountryName> list = crit.list();"
Could someone take a look at it and if anything is unclear, please say so.


Last edited by aukemid on Tue Apr 13, 2010 7:12 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: IllegalArgumentException - getter method of property: id
PostPosted: Mon Apr 12, 2010 5:43 am 
Regular
Regular

Joined: Wed Mar 10, 2010 4:48 am
Posts: 106
Someone?

I've added a part of the log:
Code:
TRACE - (HibernateMain.java:26) - Testing: 1
DEBUG - (AbstractBatcher.java:410) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG - (ConnectionManager.java:444) - opening JDBC connection
TRACE - (DriverManagerConnectionProvider.java:116) - total checked-out connections: 0
TRACE - (DriverManagerConnectionProvider.java:122) - using pooled JDBC connection, pool size: 0
DEBUG - (SQLStatementLogger.java:111) - select this_.id as id50_0_, this_.country as country50_0_, this_.language as language50_0_, this_.name as name50_0_ from countryNames this_ where this_.country=? and this_.language=?
TRACE - (AbstractBatcher.java:513) - preparing statement
ERROR - (BasicPropertyAccessor.java:191) - IllegalArgumentException in class: data.Country, getter method of property: id
DEBUG - (AbstractBatcher.java:418) - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
TRACE - (AbstractBatcher.java:562) - closing statement
TRACE - (JDBCContext.java:260) - after autocommit
DEBUG - (ConnectionManager.java:427) - aggressively releasing JDBC connection
DEBUG - (ConnectionManager.java:464) - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
TRACE - (DriverManagerConnectionProvider.java:152) - returning connection to pool, pool size: 1
TRACE - (AbstractFlushingEventListener.java:81) - flushing session
DEBUG - (AbstractFlushingEventListener.java:134) - processing flush-time cascades
TRACE - (Cascade.java:138) - processing cascade ACTION_SAVE_UPDATE for: data.Store
TRACE - (Cascade.java:173) - done processing cascade ACTION_SAVE_UPDATE for: data.Store
DEBUG - (AbstractFlushingEventListener.java:177) - dirty checking collections
TRACE - (AbstractFlushingEventListener.java:194) - Flushing entities and processing referenced collections
DEBUG - (Collections.java:199) - Collection found: [data.Store.passes#Auke], was: [data.Store.passes#Auke] (uninitialized)
DEBUG - (Collections.java:199) - Collection found: [data.Store.cameras#Auke], was: [data.Store.cameras#Auke] (uninitialized)
DEBUG - (Collections.java:199) - Collection found: [data.Store.transactions#Auke], was: [data.Store.transactions#Auke] (uninitialized)
DEBUG - (Collections.java:199) - Collection found: [data.Store.storeMaps#Auke], was: [data.Store.storeMaps#Auke] (uninitialized)
DEBUG - (Collections.java:199) - Collection found: [data.Store.storeSchedules#Auke], was: [data.Store.storeSchedules#Auke] (uninitialized)
DEBUG - (Collections.java:199) - Collection found: [data.Store.storeCalendars#Auke], was: [data.Store.storeCalendars#Auke] (uninitialized)
DEBUG - (Collections.java:199) - Collection found: [data.Store.workSchedules#Auke], was: [data.Store.workSchedules#Auke] (uninitialized)
DEBUG - (Collections.java:199) - Collection found: [data.Store.workCalendars#Auke], was: [data.Store.workCalendars#Auke] (uninitialized)
DEBUG - (Collections.java:199) - Collection found: [data.Store.storeModules#Auke], was: [data.Store.storeModules#Auke] (uninitialized)
DEBUG - (Collections.java:199) - Collection found: [data.Store.storePasses#Auke], was: [data.Store.storePasses#Auke] (uninitialized)
DEBUG - (Collections.java:199) - Collection found: [data.Store.storeEmployees#Auke], was: [data.Store.storeEmployees#Auke] (uninitialized)
DEBUG - (Collections.java:199) - Collection found: [data.Store.employeeRules#Auke], was: [data.Store.employeeRules#Auke] (uninitialized)
DEBUG - (Collections.java:199) - Collection found: [data.Store.ingredientContacts#Auke], was: [data.Store.ingredientContacts#Auke] (uninitialized)
DEBUG - (Collections.java:199) - Collection found: [data.Store.contacts#Auke], was: [data.Store.contacts#Auke] (uninitialized)
DEBUG - (Collections.java:199) - Collection found: [data.Store.positions#Auke], was: [data.Store.positions#Auke] (uninitialized)
DEBUG - (Collections.java:199) - Collection found: [data.Store.rules#Auke], was: [data.Store.rules#Auke] (uninitialized)
DEBUG - (Collections.java:199) - Collection found: [data.Store.measurements#Auke], was: [data.Store.measurements#Auke] (uninitialized)
DEBUG - (Collections.java:199) - Collection found: [data.Store.ingredients#Auke], was: [data.Store.ingredients#Auke] (uninitialized)
DEBUG - (Collections.java:199) - Collection found: [data.Store.saleTypes#Auke], was: [data.Store.saleTypes#Auke] (uninitialized)
DEBUG - (Collections.java:199) - Collection found: [data.Store.currencies#Auke], was: [data.Store.currencies#Auke] (uninitialized)
DEBUG - (Collections.java:199) - Collection found: [data.Store.discounts#Auke], was: [data.Store.discounts#Auke] (uninitialized)
DEBUG - (Collections.java:199) - Collection found: [data.Store.layouts#Auke], was: [data.Store.layouts#Auke] (uninitialized)
TRACE - (AbstractFlushingEventListener.java:233) - Processing unreferenced collections
TRACE - (AbstractFlushingEventListener.java:247) - Scheduling collection removes/(re)creates/updates
DEBUG - (AbstractFlushingEventListener.java:108) - Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
DEBUG - (AbstractFlushingEventListener.java:114) - Flushed: 0 (re)creations, 0 updates, 0 removals to 22 collections
DEBUG - (Printer.java:106) - listing entities:
DEBUG - (Printer.java:113) - data.Store{transactions=<uninitialized>, currencies=<uninitialized>, storeCalendars=<uninitialized>, ingredientContacts=<uninitialized>, passes=<uninitialized>, contacts=<uninitialized>, ingredients=<uninitialized>, id=Auke, storeSchedules=<uninitialized>, discounts=<uninitialized>, name=Test store Auke, storeMaps=<uninitialized>, saleTypes=<uninitialized>, storeOwner=null, cameras=<uninitialized>, employeeRules=<uninitialized>, franchise=data.Franchise#Auke-yyyy-DDD-kk-mm-ss-SSS-0001, storeModules=<uninitialized>, image=null, storeEmployees=<uninitialized>, workCalendars=<uninitialized>, stampMultiplier=1.0, rules=<uninitialized>, ip=null, measurements=<uninitialized>, positions=<uninitialized>, storeNumber=null, address=null, storePasses=<uninitialized>, language=data.Language#Auke-yyyy-DDD-kk-mm-ss-SSS-0001, layouts=<uninitialized>, workSchedules=<uninitialized>}
TRACE - (AbstractFlushingEventListener.java:313) - executing flush
TRACE - (ConnectionManager.java:492) - registering flush begin
TRACE - (ConnectionManager.java:501) - registering flush end
DEBUG - (ConnectionManager.java:427) - aggressively releasing JDBC connection
TRACE - (AbstractFlushingEventListener.java:344) - post flush
TRACE - (SessionImpl.java:300) - closing session
TRACE - (ConnectionManager.java:398) - connection already null in cleanup : no action


Top
 Profile  
 
 Post subject: Re: IllegalArgumentException - getter method of property: id
PostPosted: Mon Apr 12, 2010 7:11 am 
Newbie

Joined: Tue Mar 23, 2010 9:04 am
Posts: 6
I think it is a Serializable problem.


Top
 Profile  
 
 Post subject: Re: IllegalArgumentException - getter method of property: id
PostPosted: Tue Apr 13, 2010 6:27 am 
Regular
Regular

Joined: Wed Mar 10, 2010 4:48 am
Posts: 106
I came across this problem in some other mappings and the problem is probably in this peace of code:
Code:
<properties name="countryLanguageUnique" unique="true">
   <many-to-one name="country" class="data.Country" column="country" not-null="true" />
   <many-to-one name="language" class="data.Language" column="language" not-null="true" />
</properties>

I think because the many-to-one's aren't seen as properties, just as FK's.
Does anyone has a similar data structure working?


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.