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.