Code and mapping files are as follows
Hibernate version:
NHibernate 1.2
Mapping documents:
<class name="ClassLibrary1.Foo, ClassLibrary1"
table="tblProductEvent">
<id name="ID" column="ID" type="Int64">
<generator class="identity" />
</id>
</class>
DAOs:
public interface IFoo
{
long ID { get; set; }
}
--
public class Foo : IFoo
{
private long m_ID;
public long ID
{
get { return m_ID; }
set { m_ID = value; }
}
}
Code between sessionFactory.openSession() and session.close():
Foo f = (Foo)session.Load(typeof(IFoo), (long) 358144);
Full stack trace of any exception that occurs:
"Unknown entity class: ClassLibrary1.IFoo"
Name and version of the database you are using:
Sybase 12.5.4
Comment:
I understand that IFoo is not defined in the mapping file, but in the documentation there is a very similar example with IProduct and this works (i.e. implicit polymorphism seems to be what makes it work).
Possible solution -- unfortunately not working either:
Further, I then tried to change the mapping file to:
<class name="ClassLibrary1.IFoo, ClassLibrary1"
table="tblProductEvent"
discriminator-value="0">
<id name="ID" column="ID" type="Int64">
<generator class="identity" />
</id>
<discriminator column="EventTypeID" type="Int64"/>
<subclass name="ClassLibrary1.Foo, ClassLibrary1" discriminator-value="7">
</subclass>
</class>
This works when loading with typeof(Foo) instead of typeof(IFoo). However it still file if I try to load with IFoo (but with a different error message):
{"Unable to cast object of type 'ProxyInterfaceSystemSystemObject_ClassLibrary1IFoo_NHibernate_ProxyINHibernateProxy_System_Runtime_SerializationISerializable' to type 'ClassLibrary1.Foo'."}
This looks like Hibernate did not find out about the concrete type of the passed ID, but I'm sure it has the discriminator set as specified in the mapping file.
Conclusion:
In my opinion, both versions should work (even though I don't know which one is better, any ideas?). Can anyone help?
Thanks a lot!
|