-->
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: Unmapped class error using interface class as proxy
PostPosted: Fri Jul 08, 2005 9:30 pm 
Newbie

Joined: Fri Jul 08, 2005 8:45 pm
Posts: 4
Trying to get the mapping file to behave. We're using paired interface and impl classes for each object. PurchaseOrder and PurchaseOrderImpl. Both kinds have abstract superclasses.

I found this on page 167 of the 3.0.5 reference manual:

Quote:
your persistent classes must each implement an interface that declares its business methods.
You should specify these interfaces in the mapping file. eg.


Code:
<class name="CatImpl" proxy="Cat">
......
<subclass name="DomesticCatImpl" proxy="DomesticCat">
.....
</subclass>
</class>

where CatImpl implements the interface Cat and DomesticCatImpl implements the interface DomesticCat.

Then proxies for instances of Cat and DomesticCat may be returned by load() or iterate(). (Note that list() does not usually return proxies.)
Code:
Cat cat = (Cat) session.load(CatImpl.class, catid);
Iterator iter = session.iterate("from CatImpl as cat where cat.name='fritz'");
Cat fritz = (Cat) iter.next();

Relationships are also lazily initialized. This means you must declare any properties to be of type Cat, not CatImpl


But I got this
Code:
.org.hibernate.MappingException: Association references unmapped class: orderentry.PurchaseOrder
   at org.hibernate.cfg.HbmBinder.bindCollectionSecondPass(HbmBinder.java:1948)
   at org.hibernate.cfg.HbmBinder$CollectionSecondPass.secondPass(HbmBinder.java:2364)
   at org.hibernate.cfg.HbmBinder$SecondPass.doSecondPass(HbmBinder.java:2335)
   at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:860)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1048)


When I tried running with this:

Code:
<?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 auto-import="false">
   <class name="orderentry.impl.OrderEntryElementImpl" table="OrderEntryElement" proxy="orderentry.OrderEntryElement">
      <id name="orderEntryElementID" type="long" length="50" column="orderEntryElementID" unsaved-value="0">
         <generator class="native"/>
      </id>
      <many-to-one name="aggby" class="orderentry.OrderEntryModel" cascade="save-update">
         <column name="aggby_OrderEntryModel" not-null="true"/>
      </many-to-one>
      <joined-subclass name="orderentry.impl.AddressImpl" extends="orderentry.impl.OrderEntryElementImpl" table="Address" proxy="orderentry.Address">
         <key column="orderEntryElementID"/>
         <bag name="shippingAddressFor" access="runtime.hibernate.CollectionBasicPropertyAccessor" inverse="true">
            <key column="shipTo_Address"/>
            <one-to-many class="orderentry.PurchaseOrder"/>
         </bag>
      </joined-subclass>
      <joined-subclass name="orderentry.impl.PurchaseOrderImpl" extends="orderentry.impl.OrderEntryElementImpl" table="PurchaseOrder" proxy="orderentry.PurchaseOrder">
         <key column="orderEntryElementID"/>
         <many-to-one name="customer" class="orderentry.Customer" cascade="save-update">
            <column name="customer_Customer" not-null="true"/>
         </many-to-one>
      </joined-subclass>
   </class>
   <class name="orderentry.impl.OrderEntryModelImpl" table="OrderEntryModel" proxy="orderentry.OrderEntryModel">
      <id name="orderEntryModelID" type="long" length="50" column="orderEntryModelID" unsaved-value="0">
         <generator class="native"/>
      </id>
      <bag name="aggs" access="runtime.hibernate.CollectionBasicPropertyAccessor" inverse="true" cascade="all">
         <key column="aggby_OrderEntryModel"/>
         <one-to-many class="orderentry.OrderEntryElement"/>
      </bag>
   </class>
</hibernate-mapping>


I thought it might be the bags, but I deleted them and got unmapped class errors with my many-to-ones, also.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 10:10 pm 
Beginner
Beginner

Joined: Fri Jul 08, 2005 12:38 pm
Posts: 41
Location: Massachusetts, USA
The exception indicates that you don't have a mapping for PurchaseOrder. There isn't a mapping for this class in your post -- do you have it in another file?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 09, 2005 2:01 pm 
Newbie

Joined: Fri Jul 08, 2005 8:45 pm
Posts: 4
PurchaseOrder is the interface class that I want to use. PurchaseOrderImpl is the persistent class. Therefore I didn't map PurchaseOrder (as the example from the doc shows.)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 09, 2005 2:09 pm 
Senior
Senior

Joined: Thu May 12, 2005 11:40 pm
Posts: 125
Location: Canada
My understanding is that this is done by pointing the <class> to the interface, and nesting a <subclass> that points to the implementation. You don't actually have to map the abstract superclass anywhere if all it does is centralize common functionality and has no persistent properties.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 09, 2005 3:53 pm 
Newbie

Joined: Fri Jul 08, 2005 8:45 pm
Posts: 4
Hmm. The example doesn't show that. Of course, my Impl classes already have a superclass. You're saying the example above should look like this?

<class name="Cat">
...
<subclass name="CatImpl" proxy="Cat">
...
</subclass>
</class>

<class name="DomesticCat">
...
<subclass name="DomesticCatImpl" proxy="DomesticCat">
...
</subclass>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 09, 2005 5:29 pm 
Senior
Senior

Joined: Thu May 12, 2005 11:40 pm
Posts: 125
Location: Canada
I've never done this, so I don't know if it actually works, or if it works exactly like that. However, on page 51 of the reference documentation pdf:

Quote:
It is perfectly acceptable for the named persistent class to be an interface. You would then declare implementing
classes of that interface using the <subclass> element.


Top
 Profile  
 
 Post subject: Happy ending
PostPosted: Mon Jul 11, 2005 6:11 pm 
Newbie

Joined: Fri Jul 08, 2005 8:45 pm
Posts: 4
Didn't need to explicitly identify proxies after all in our case. Only needed to (stupid, stupid) use the 3.0 DTD in the mapping file.

Thanks for your help, all.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 11:40 am 
Beginner
Beginner

Joined: Mon Feb 23, 2004 5:11 pm
Posts: 39
I am having the same problem (unmapped class on proxy interfaces). I am not clear on what you did to fix the issue. what does this mean "Didn't need to explicitly identify proxies after all in our case ". Any help would be appreciated.


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.