-->
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.  [ 1 post ] 
Author Message
 Post subject: 2 problems with implicit polymorphism
PostPosted: Mon Nov 12, 2007 7:44 am 
Newbie

Joined: Mon Nov 12, 2007 7:18 am
Posts: 1
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.