-->
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.  [ 3 posts ] 
Author Message
 Post subject: SEVERE: IllegalArgumentException in class.....
PostPosted: Tue May 18, 2010 11:26 pm 
Newbie

Joined: Tue May 18, 2010 10:40 pm
Posts: 2
Hi All,
I am attempting make a small application work using hibernate (Hibernate 3.2.6). However I am stuck at this problem
As you can see in the debug code that The query successfully prints the value from one table(packageId:13) but when it goes to the second table that is linked within, thats where it fails
here is the exception
Code:
Hibernate: select guestpacka0_.GUEST_PACKAGE_ID as col_0_0_ from GUEST_PACKAGE guestpacka0_
packageId:13
Hibernate: select guestpacka0_.GUEST_PACKAGE_ID as GUEST1_1_0_, guestpacka0_.season_id as season2_1_0_, guestpacka0_.rental_nightly_rate as rental3_1_0_, guestpacka0_.rental_weekly_rate as rental4_1_0_, guestpacka0_.create_date as create5_1_0_, guestpacka0_.created_by as created6_1_0_, guestpacka0_.update_date as update7_1_0_, guestpacka0_.updated_by as updated8_1_0_, guestpacka0_.guest_id as guest9_1_0_, guestpacka0_.unit_id as unit10_1_0_, guestpacka0_.week_id as week11_1_0_ from GUEST_PACKAGE guestpacka0_ where guestpacka0_.GUEST_PACKAGE_ID=?
May 18, 2010 9:09:25 PM org.hibernate.property.BasicPropertyAccessor$BasicSetter set
SEVERE: IllegalArgumentException in class: com.webapplikations.rvvressys.hibernate.GuestPackage, setter method of property: guestId
May 18, 2010 9:09:25 PM org.hibernate.property.BasicPropertyAccessor$BasicSetter set
SEVERE: expected type: java.lang.Long, actual value: com.webapplikations.rvvressys.hibernate.Guest$$EnhancerByCGLIB$$3c3d149b
May 18, 2010 9:09:25 PM org.hibernate.event.def.DefaultLoadEventListener onLoad
INFO: Error performing load command
org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.webapplikations.rvvressys.hibernate.GuestPackage.guestId
   at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:104)
   at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:337)
   at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:200)
   at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3571)
   at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:133)
   at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
   at org.hibernate.loader.Loader.doQuery(Loader.java:729)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
   at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3049)
   at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:399)
   at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)
   at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:98)
   at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
   at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:836)
   at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:66)
   at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
   at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
   at com.webapplikations.rvvressys.hibernate.GuestPackage$$EnhancerByCGLIB$$7de2ad3f.getGuestId(<generated>)
   at Main.main(Main.java:108)
   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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:110)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
   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)


There are 2 classes Guest(Guest.hbm.xml) and GuestPackage(GuestPackage.hbm.xml)
Guest class has a one-to-many relationship with GuestPackage
Code:
Guest.hbm.xml
<?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.webapplikations.rvvressys.hibernate.Guest" table="GUEST">
            <id column="GUEST_ID" name="guestId" type="java.lang.Long">
                <generator class="identity"/>               
            </id>
            <property column="guest_type_id" name="guestTypeId" type="java.lang.Long"/>
            <property column="guest_name" name="guestName" type="java.lang.String"/>
            <property column="address" name="address" type="java.lang.String"/>
            <property column="email" name="email" type="java.lang.String"/>
            <property column="phone" name="phone" type="java.lang.String"/>
            <property column="comments" name="comments" type="java.lang.String"/>



            <property column="create_date" name="createDate" type="java.sql.Date"/>
            <property column="created_by" name="createdBy" type="java.lang.Long"/>
            <property column="update_date" name="updateDate" type="java.sql.Date"/>
            <property column="updated_by" name="updatedBy" type="java.lang.Long"/>

            <set name="guestPackages" inverse="true" >
                <key column="guest_id"/>
                <one-to-many class="com.webapplikations.rvvressys.hibernate.GuestPackage" />
            </set>

        </class>
    </hibernate-mapping>
----------------------------------------------------------------
GuestPackage.hbml.xml
<?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.webapplikations.rvvressys.hibernate.GuestPackage" table="GUEST_PACKAGE">
            <id column="GUEST_PACKAGE_ID" name="guestPackageId" type="java.lang.Long">
                <generator class="identity"/>
            </id>

            <property column="season_id" name="seasonId" type="java.lang.Long"/>

            <property column="rental_nightly_rate" name="rentalNightlyRate" type="double"/>
            <property column="rental_weekly_rate" name="rentalWeeklyRate" type="double"/>

            <property column="create_date" name="createDate" type="java.sql.Date"/>
            <property column="created_by" name="createdBy" type="java.lang.Long"/>
            <property column="update_date" name="updateDate" type="java.sql.Date"/>
            <property column="updated_by" name="updatedBy" type="java.lang.Long"/>

            <many-to-one class="com.webapplikations.rvvressys.hibernate.Guest" name="guestId" column="guest_id" not-null="false"/>

        </class>
    </hibernate-mapping>


in class GuestPackage.java I have the getter and setter methods where exception is pointing to as below
Code:
    public Long getGuestId() {
        return guestId;
    }

    public void setGuestId(Long guestId) {
        this.guestId = guestId;
    }


in the data base there are some foreignkey columns that are null
I am extremely beginner, actually started last weekend and have gotten stuck here...can some kind soul shed some light?
the colunm guest_id in db is of type int (I tried to change it to different numeric types with no luck)
databse is MS SQL


Top
 Profile  
 
 Post subject: Re: SEVERE: IllegalArgumentException in class.....
PostPosted: Wed May 19, 2010 3:38 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
The <many-to-one> mapping for guest:

Code:
<many-to-one class="com.webapplikations.rvvressys.hibernate.Guest" name="guestId" column="guest_id" not-null="false"/>


doesn't match your code:

Code:
public Long getGuestId() {
     return guestId;
}

public void setGuestId(Long guestId) {
    this.guestId = guestId;
}


Your getter and setters for a <many-to-one> should use the same parameter/return type as specified by the class attribute. It doesn't really matter but for readability reasons I also recommend that you change the name to "guest".

Code:
<many-to-one class="com.webapplikations.rvvressys.hibernate.Guest" name="guest" column="guest_id" not-null="false"/>

public Guest getGuest() {
     return guest;
}

public void setGuest(Guest guest) {
    this.guest = guest;
}


Top
 Profile  
 
 Post subject: Re: SEVERE: IllegalArgumentException in class.....
PostPosted: Wed May 19, 2010 11:28 am 
Newbie

Joined: Tue May 18, 2010 10:40 pm
Posts: 2
Thanks a bunch, that was it. So for my understanding, in many-to-one the name property should be pointing to the class object that is given in the class property

Code:
<many-to-one class="com.webapplikations.rvvressys.hibernate.Guest" name="guest" column="guest_id" not-null="false"/>


Where as the column is the FK column


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