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: