-->
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 loading proxy using interface
PostPosted: Tue Oct 05, 2004 12:39 pm 
Newbie

Joined: Mon Sep 13, 2004 1:20 pm
Posts: 3
Location: Boulder, CO
Here, an Org object has a many-to-one reference to a User object, which is mapped as using an interface proxy. When the Org object is loaded, when Hibernate tries to call the setUser method on Org, it only has a proxy that implements IRep and IUser, but the setter method requires a User object, so Java throws IllegalArgumentException. I tried mapping the many-to-one to the interface -- IUser, but then I get a Hibernate startup error
Quote:
An association from the table Org refers to an unmapped class: com.kingland.tapestre.user.IUser
. Can you tell me what I'm doing wrong? Thanks!



Hibernate version: 2.1 (bundled with MyEclipse 3.8.2)

Mapping documents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping package="com.xyz.newprod.bd">
<meta attribute="use-in-tostring">true</meta>

<!-- /////////////// Org ///////////////// -->

<class name="Org">
<id name="id" type="integer">
<meta attribute="scope-set">private</meta>
<meta attribute="scope-get">private</meta>
<generator class="native"/>
</id>
<property name="primaryKey"
type="com.xyz.newprod.hibernate.IntegerPrimaryKeyUT" formula="id">
<meta attribute="scope-set">private</meta>
</property>
<property name="name" type="string" length="30" not-null="true"/>
<many-to-one name="parent" column="parentId" outer-join="false"
class="com.xyz.newprod.bd.Org" cascade="none"/>
<many-to-one name="contact" column="contactId" outer-join="false"
class="com.xyz.newprod.common.Contact" cascade="all"
unique="true"/>
<many-to-one name="manager" column="managerId" outer-join="false"
class="com.xyz.newprod.user.User" cascade="none"/>
</class>

</hibernate-mapping>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">


<hibernate-mapping package="com.xyz.newprod.user">

<class name="User" proxy="com.xyz.newprod.user.IUser">

<id name="id" type="integer">
<meta attribute="scope-set">private</meta>
<meta attribute="scope-get">protected</meta>
<meta attribute="use-in-tostring">true</meta>
<generator class="native"/>
</id>
<timestamp name="updateDate"/>
<property name="primaryKey"
type="com.xyz.newprod.hibernate.IntegerPrimaryKeyUT" formula="id">
<meta attribute="scope-set">private</meta>
</property>
<property name="firstName" type="string" length="50"/>
<property name="lastName" type="string" length="50" not-null="true"/>
<property name="login" type="string" length="16" not-null="true" unique="true"/>
<property name="status"
type="com.xyz.newprod.hibernate.UserStatusUT">
<column name="StatusId" length="1" not-null="true" check="StatusId in ('A','I','T')"/>
</property>

<joined-subclass name="Rep" proxy="com.xyz.newprod.user.IRep">
<key column="userId"/>
<property name="ssn" type="string" length="11"/>
<property name="birthDate" type="date"/>
</joined-subclass>

</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

return getHibernateSession().load( Org.class, new Integer(2) );

Full stack trace of any exception that occurs:

com.xyz.foundation.exception.PersistenceException: net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.kingland.tapestre.bd.Org.manager
at com.xyz.newprod.bd.BdDaoImpl.find(BdDaoImpl.java:21)
at com.xyz.newprod.test.Test1.main(Test1.java:89)
Caused by: net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.xyz.newprod.bd.Org.manager
at net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:68)
at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:221)
at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2199)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:240)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:836)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:856)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:59)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:51)
at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:419)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2106)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1980)
at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1909)
at com.xyz.newprod.bd.BdDaoImpl.find(BdDaoImpl.java:18)
... 1 more
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:324)
at net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:38)
... 14 more
Exception in thread "main"

Name and version of the database you are using:

DB2 for I5 series, V5R3

The generated SQL (show_sql=true):

select org0_.id as id1_, org0_.name as name1_, org0_.level as level1_, org0_.parentId as parentId1_, org0_.contactId as contactId1_, org0_.managerId as managerId1_, org0_.id as f1_1_, orgconfig1_.level as level0_, orgconfig1_.singularName as singular2_0_, orgconfig1_.pluralName as pluralName0_, orgconfig1_.description as descript4_0_ from Org org0_ left outer join OrgConfig orgconfig1_ on org0_.level=orgconfig1_.level where org0_.id=?


Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject: IllegalArgumentException loading proxy using interface
PostPosted: Tue Dec 07, 2004 8:35 pm 
Newbie

Joined: Fri Dec 03, 2004 9:44 pm
Posts: 6
Location: Eugene, OR
I'm having a very similiar problem where my domain is defined using interfaces, including a number of setter methods for domain objects. Whenever Hibernate tries to use one of the setters, I get an IllegalArgumentException

Code:
SEVERE: IllegalArgumentException in class: com.mckesson.lab.tc.objects.CodeValueImpl, setter method of property: type
net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter set
SEVERE: expected type: com.mckesson.lab.tc.objects.CodeTypeImpl, actual value: net.sf.hibernate.proxy.HibernateProxy$$EnhancerByCGLIB$$a77bb5ca
Dec 7, 2004 4:04:07 PM net.sf.hibernate.proxy.LazyInitializer initializeWrapExceptions
SEVERE: Exception initializing proxy


I think this is because my setter method takes the interface as a parameter, not the bean.

Did you ever find a workaround?

Richard


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 07, 2004 8:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
looks like your setter method needs to accept the interface type


Top
 Profile  
 
 Post subject: Interface Types
PostPosted: Thu Dec 09, 2004 3:32 pm 
Newbie

Joined: Fri Dec 03, 2004 9:44 pm
Posts: 6
Location: Eugene, OR
I went completely through the code with a fine tooth comb. In this particular case, the setter method was not part of the interface, so when the setter method was implemented, the wrong type for the parameter was used.

Thanks for your response.

Richard


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.