I am experimenting with custom persisters, specifically with relationships betwen db-persisted entities and custom-persisted entities. Unfortunately when I try to create a many-to-one relationship from a db-persisted entity to a custom-persisted entity I get a ClassCastException. The code in org.hibernate.persister.collection.AbstractCollectionPersister.getElementPersister(AbstractCollectionPersister.java:1179)
is casting the persister to a Loadable.
I am using MasterDetail.hbm.xml and Custom.hbm.xml. I have added a set of Custom objects to the Master class definition. When I try to run MasterDetailTest as a java application I get the exception (shown below).
Can anyone give me any pointers as to whether it is possible to get relationships working between entities persisted with different persisters?
I have tried this with NHibernate 1.0.1, hibernate 2.1.6 and 3.0 with similar results.
Thanks in anticipation!
Hibernate version:
2.1 & 3.0 & NHibernate 1.0.1
Mapping documents:
I used MasterDetail.hbm.xml & Custom.hbm.xml. Amended MasterDetail.hbm.xml to add:
Code:
<set name="customs" lazy="true">
<key/>
<one-to-many class="org.hibernate.test.legacy.Custom"/>
</set>
to mapping for org.hibernate.test.legacy.Master class. I have added appropriate code to Master.java:
Code:
private Collection customs;
public Collection getCustoms() {
return customs;
}
public void setCustoms(Collection customs) {
this.customs = customs;
}
Code between sessionFactory.openSession() and session.close():N/A. I am running org.hibernate.test.legacy.MasterDetailTest as a java application
Full stack trace of any exception that occurs:java.lang.ClassCastException: org.hibernate.test.legacy.CustomPersister
at org.hibernate.persister.collection.AbstractCollectionPersister.getElementPersister(AbstractCollectionPersister.java:1179)
at org.hibernate.loader.collection.OneToManyLoader.<init>(OneToManyLoader.java:84)
at org.hibernate.loader.collection.OneToManyLoader.<init>(OneToManyLoader.java:69)
at org.hibernate.loader.collection.OneToManyLoader.<init>(OneToManyLoader.java:60)
at org.hibernate.loader.collection.BatchingCollectionInitializer.createBatchingOneToManyInitializer(BatchingCollectionInitializer.java:72)
Name and version of the database you are using:hsql 1.7.1
The generated SQL (show_sql=true):N/A
Debug level Hibernate log excerpt:N/A
Code: