-->
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.  [ 8 posts ] 
Author Message
 Post subject: Using return-join throws IllegalArgumentException
PostPosted: Tue Apr 18, 2006 10:39 pm 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
Hi,
We have a Parent(which has a primitive id) and a child which has composite id. We are trying to use the sql-query and the result-join to get going but are running into IllegalArgumentException. Here's our mapping:

Parent Mapping
Code:
<hibernate-mapping default-lazy="false">
   <class name="com.dbdata.system.dbmeta.DbMeta" table="TAP_DBMETA_ROOT">
      <id name="dbMetaId" column="DBMETA_ID" type="integer">
         <generator class="assigned"/>
      </id>
      <property name="name" type="string" column="NAME"/>
      
      
      <set fetch="join" name="schemas" cascade="all-delete-orphan" inverse="true">
         <key column="DBMETA_ID"/>
         <one-to-many class="com.dbdata.system.dbmeta.Schema"/>
      </set>
      
      <loader query-ref="loadDbMeta"/>
   </class>
      
       <sql-query name="loadDbMeta">
         <return alias="dbMeta" class="com.dbdata.system.dbmeta.DbMeta"/>
           [b]<return-join alias="schema" property="dbMeta.schemas"/>[/b]         
      
      
      
           SELECT {dbMeta.*},
                   {schema.*}
           FROM DBMETA_ROOT DBMETA
             LEFT JOIN DBMETA_SCHEMA SCHEMA
              ON DBMETA.DBMETA_ID = SCHEMA.PARENT_DBMETA_ID
                  WHERE DBMETA.DBMETA_ID = :dbMetaId
         </sql-query>
      
</hibernate-mapping>


Child mapping
Code:
<hibernate-mapping default-lazy="false">
   <class name="com.dbdata.system.dbmeta.Schema" table="TAP_DBMETA_SCHEMA">
      <composite-id name="pkId" class="com.dbdata.system.dbmeta.keys.SchemaID">
         <key-property name="dbMetaId" column="DBMETA_ID" type="integer"/>
         <key-property name="schemaId" column="SCHEMA_ID" type="integer"/>
      </composite-id>
      <property name="name" type="string" column="NAME"/>
      
      <many-to-one name="parent" class="com.dbdata.system.dbmeta.DbMeta" column="PARENT_DBMETA_ID" not-null="true"/>
      
</class>
</hibernate-mapping>


Here's the exception:

Quote:
ERROR 18 Apr 16:07:48 [main] org.hibernate.property.BasicPropertyAccessor - IllegalArgumentException in class: com.dbdata.system.dbmeta.keys.SchemaID, getter method of property: dbMetaId INFO 18 Apr 16:07:48 [main] org.hibernate.event.def.DefaultLoadEventListener - Error performing load command
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.dbdata.system.dbmeta.keys.SchemaID.dbMetaId
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
at org.hibernate.tuple.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:121)
at org.hibernate.tuple.AbstractComponentTuplizer.getPropertyValues(AbstractComponentTuplizer.java:133)
at org.hibernate.tuple.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.java:88)
at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:307)
at org.hibernate.type.ComponentType.isEqual(ComponentType.java:122)
at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1095)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:554)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:111)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1674)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:147)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:164)
at org.hibernate.persister.entity.NamedQueryLoader.load(NamedQueryLoader.java:57)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2730)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:161)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:891)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:810)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:803)
at com.dbdata.system.dbmeta.HibernateTester.getObject(HibernateTester.java:45)
at com.dbdata.system.dbmeta.HibernateTester.retrieveObject(HibernateTester.java:87)
at com.dbdata.system.dbmeta.HibernateTester.main(HibernateTester.java:326)
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:324)
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
... 29 more


I had a look at the code and at:

Code:
public Object get(Object target) throws HibernateException {
         try {
            return method.invoke(target,null);
         }catch (IllegalArgumentException iae) {
            log.error(
                  "IllegalArgumentException in class: " + clazz.getName() +
                  ", getter method of property: " + propertyName
               );
            throw new PropertyAccessException(
                  iae,
                  "IllegalArgumentException occurred calling",
                  false,
                  clazz,
                  propertyName
               );      }


Here the 'target' parameter passed to this method is of type Integer (instead of com.dbdata.system.dbmeta.keys.SchemaID) and the method getDbMetaId in invoked on this object of type Integer and hence resulting in the exception.

Does anyone have any idea why this is happening? Anything wrong with the mapping or the query?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 11:10 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
What type does Schema.getPkId() return? The exception suggests that it's returning an Integer, but your mapping requires it to return a SchemaID.

Also note that your sql-query should (probably?) be using load-collection, not return-join. return-join is for associations, not collections. If your query returned a Schema and its associated DbMeta, then you'd use return-join, but it's returning a DbMeta and all its Schema objects.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 19, 2006 6:38 am 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
tenwit wrote:
What type does Schema.getPkId() return? The exception suggests that it's returning an Integer, but your mapping requires it to return a SchemaID.


Well, the Schema.getPkId returns SchemaID. Here's the code:

Code:
public class Schema {
    DbMeta _parent;
   
    SchemaID _pkId;
   
   
   public Schema() {
            
   }
   
    public Schema(Object dbMetaId, Object schemaId) {
                _pkId = new SchemaID(dbMetaId, schemaId);
      }
   
    public SchemaID getPkId(){
        return _pkId;
    }
   
    public void setPkId(SchemaID pkId){
        _pkId = pkId;
    }
   
    public Object getDbMetaId() {
        return _pkId.getDbMetaId();
    }
   
    public Object getSchemaId() {
        return _pkId.getSchemaId();
    }
   
    public DbMeta getParent() {
        return _parent;
    }

    public void setParent(DbMeta parent) {
        this._parent = parent;
    }

}


Code:
public class SchemaID implements Serializable{
    Object _dbMetaId;
    Object _schemaId;
   
   public SchemaID() {
      super();
   }
   
    public SchemaID(Object dbMetaId, Object schemaId) {
        super();
        _dbMetaId = dbMetaId;
        _schemaId = schemaId;
    }
   
    public Object getDbMetaId(){
        return _dbMetaId;
    }

    public void setDbMetaId(Object id){
        _dbMetaId = id;
    }
   
    public Object getSchemaId(){
        return _schemaId;
    }

    public void setSchemaId(Object id){
        _schemaId = id;
    }
   
    public boolean equals(Object obj){
        boolean retVal = false;
       
        if (this == obj) {
            retVal = true;
        } else if ((obj == null) || !(getClass().equals(obj.getClass()))) {
            retVal = false;
        }else{
            retVal = ((_dbMetaId.equals(((SchemaID)obj).getDbMetaId())) &&
                      (_schemaId.equals(((SchemaID)obj).getSchemaId())));
        }
        return retVal;
    }
   
    public int hashCode(){
       return (((Integer)_dbMetaId).intValue() << 24 + ((Integer)_schemaId).intValue());
    }
}



Quote:
Also note that your sql-query should (probably?) be using load-collection, not return-join. return-join is for associations, not collections. If your query returned a Schema and its associated DbMeta, then you'd use return-join, but it's returning a DbMeta and all its Schema objects.


I will try this out.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 19, 2006 5:41 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I notice that getDbMetaId() (and getSchemaId()) return Objects, rather than Integers as your mapping file requires. I don't think that's the problem, but it might be. See what happens if you change those to Integers.

Are you using 3.1+? If you are, try adding property-ref="parent" to the one-to-many mapping. Again, it's a stab in the dark, but it might help. I'm not even sure that that's the right syntax, I'm still using 3.0.5 which doesn't support property-ref on one-to-many...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 2:32 pm 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
I tried out the load-collection approach, but it failed with the same exception.

I am using Hibernate-3.1.2, and will try out your above mentioned suggestions.

-Jaikiran


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 1:37 pm 
Newbie

Joined: Fri Apr 07, 2006 6:04 pm
Posts: 12
I have a similar problem using a List. Was any definite solution found?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 29, 2006 9:16 am 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
No. I havent yet found a solution. We tried out all the options that were suggested here


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

Joined: Fri Apr 07, 2006 6:04 pm
Posts: 12
Thanks.


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