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.  [ 11 posts ] 
Author Message
 Post subject: cannot create proxy (method has no implementation)
PostPosted: Thu Feb 21, 2008 12:19 pm 
Newbie

Joined: Fri Feb 15, 2008 12:13 pm
Posts: 15
NHibernate 1.2, Oracle 9

Hi,

I have an abstract class UmmConsumer and another class ConsumerAction (not abstract). Each ConsumerAction belongs to one UmmConsumer.

sessio.Load<UmmConsumer>(1) will return an instance of SendMailConsumer, which is correct.

session.Load<ConsumerAction>(2728) will throw an exception (see below). ConsumerAction#2728 belongs to UmmConsumer#1.

Since ConsumerAction has a List<UmmConsumer>, nhibernate seems to try to instanciate an instance of UmmConsumer, ignoring subclass definitions, wich leads this exception:

Quote:
NHibernate.HibernateException: Creating a proxy instance failed ---> System.TypeLoadException: Die Methode handleMessage im Typ CProxyTypeUmm_PocoUmmConsumerPoco_NHibernate_ProxyINHibernateProxy1 der Assembly DynamicAssemblyProxyGen, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null hat keine Implementierung.
bei System.Reflection.Emit.TypeBuilder.TermCreateClass(Int32 handle, Module module)
bei System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
bei System.Reflection.Emit.TypeBuilder.CreateType()
bei Castle.DynamicProxy.Builder.CodeBuilder.AbstractEasyType.BuildType()
bei Castle.DynamicProxy.Builder.CodeGenerators.BaseCodeGenerator.CreateType()
bei Castle.DynamicProxy.Builder.CodeGenerators.ClassProxyGenerator.GenerateCode(Type baseClass, Type[] interfaces)
bei Castle.DynamicProxy.Builder.DefaultProxyBuilder.CreateClassProxy(Type theClass, Type[] interfaces)
bei Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type baseClass, Type[] interfaces, IInterceptor interceptor, Boolean checkAbstract, Object[] argumentsForConstructor)
bei NHibernate.Proxy.CastleProxyFactory.GetProxy(Object id, ISessionImplementor session)
--- Ende der internen Ausnahmestapelüberwachung ---
bei NHibernate.Proxy.CastleProxyFactory.GetProxy(Object id, ISessionImplementor session)
bei NHibernate.Persister.Entity.AbstractEntityPersister.CreateProxy(Object id, ISessionImplementor session)
bei NHibernate.Impl.SessionImpl.DoLoadByClass(Type clazz, Object id, Boolean checkDeleted, Boolean allowProxyCreation)
bei NHibernate.Impl.SessionImpl.InternalLoad(Type clazz, Object id, Boolean eager, Boolean isNullable)
bei NHibernate.Type.EntityType.ResolveIdentifier(Object id, ISessionImplementor session)
bei NHibernate.Type.EntityType.ResolveIdentifier(Object id, ISessionImplementor session, Object owner)
bei NHibernate.Impl.SessionImpl.InitializeEntity(Object obj)
bei NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList hydratedObjects, Object resultSetId, ISessionImplementor session)
bei NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
bei NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
bei NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
bei NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters)
bei NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes)
bei NHibernate.Hql.Classic.QueryTranslator.List(ISessionImplementor session, QueryParameters queryParameters)
bei NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters, IList results)
bei NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters)
bei NHibernate.Impl.QueryImpl.List()
bei NHibernate.Impl.AbstractQueryImpl.UniqueResult()
bei enbw.lib.db.HibernateDAO`1.Load(Object id) in D:\VSSTools\lib\lib\db\HibernateDAO.cs:Zeile 125.



So, any idea why subclass-instanciation works for loading UmmConsumer, but not when indirectly loading UmmConsumer via property of ConsumerAction?

Thanks :)


Top
 Profile  
 
 Post subject: Re: cannot create proxy (method has no implementation)
PostPosted: Thu Feb 21, 2008 12:23 pm 
Newbie

Joined: Fri Feb 15, 2008 12:13 pm
Posts: 15
addition: handleMessage is abstract method in UmmConsumer


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 22, 2008 5:15 am 
Newbie

Joined: Fri Feb 15, 2008 12:13 pm
Posts: 15
since I'm stuck with this problem, maybe some configuration information could help?

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
   <class name="Umm.Poco.UmmConsumer, Umm" table="tb_umm_consumer" mutable="false">
      <id name="Consumer_id">
         <column name="consumer_id" not-null="true"/>
         <generator class="sequence">
            <param name="sequence">SQ_UMM_CONSUMER</param>
         </generator>
      </id>
      
      <discriminator column="consumer_type" />

      <bag name="Actions" table="tb_umm_consumeraction" lazy="true">
         <key column="consumeraction_id" />
         <one-to-many class="Umm.Poco.ConsumerAction, Umm"/>
      </bag>

      <subclass name="Umm.Consump.SendMailConsumer, Umm" />
      <subclass name="Umm.Consump.ExcelConsumer, Umm" />
      <subclass name="Umm.Consump.FileServerConsumer, Umm" />
   </class>
</hibernate-mapping>


Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
   <class name="Umm.Poco.ConsumerAction, Umm" table="tb_umm_consumeraction">
      <id name="Consumeraction_id">
         <column name="consumeraction_id" not-null="true"/>
         <generator class="sequence">
            <param name="sequence">SQ_UMM_CONSUMERACTION</param>
         </generator>
      </id>
      
      <property name="Action_id"/>

      <!-- disable insert/update to force oracle to use default value (sysdate) -->
      <property name="Ora_timestamp" insert="false" update="false"/>

      <many-to-one name="Consumer" class="Umm.Poco.UmmConsumer, Umm" column="FK_CONSUMER" not-null="true"/>
      <many-to-one name="Message" class="Umm.Poco.UmmMessage, Umm" column="FK_MSG" not-null="true"/>
   </class>
</hibernate-mapping>


any idea?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 25, 2008 9:58 am 
Newbie

Joined: Fri Feb 15, 2008 12:13 pm
Posts: 15
Still nobody any idea?

Is there any misconfiguration I can't see?


Please help..


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 25, 2008 10:11 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Have a look in http://forum.hibernate.org/viewtopic.php?t=984079, seems to be the same problem.

Have you tried to use lazy="false" on the association to UmmConsumer ?

Code:
<many-to-one name="Consumer" class="Umm.Poco.UmmConsumer, Umm" column="FK_CONSUMER" not-null="true" lazy="false"/>

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 25, 2008 12:04 pm 
Newbie

Joined: Fri Feb 15, 2008 12:13 pm
Posts: 15
wolli wrote:
Have you tried to use lazy="false" on the association to UmmConsumer ?


I'm sure I've tried every configuration possibility, but somehow this is the correct case. Setting lazy to false works.

Nevertheless, it doesnt really make a lot of sense.


thanks a lot, wolli.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 25, 2008 12:54 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Have you read the possible explanation from Symon in the other thread ? The basic idea of lazy loading is to create a proxy object instead of the real object (and without accessing the database). Since there is no way for hibernate to find out which subclass it has to use without accessing the database, the only possibility is to proxy an object of the type specified in the mapping. So in your scenario hibernate tries to subclass the abstract class and can't "implement" your abstract method.

I don't exactly know how hibernate creates proxy objects, theoretically it should be possible to override abstract methods there. But unlike properties, which are mapped to columns, for mehtods, you can't tell if the object needs to be loaded or not.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 26, 2008 3:31 am 
Newbie

Joined: Fri Feb 15, 2008 12:13 pm
Posts: 15
yep, I've read it and your explanation as well makes sense.
But I'd expected hibernate to throw a more self-explaining exception or maybe log a warning and ignore "lazy=true", if otherwise an exception would occur.

on the other hand, you can say it's just misconfiguration. I don't know.

however..thanks a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 26, 2008 4:27 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
Without seeing your code it's a little hard to tell, but this sounds like your abstract method is probably not public.

There *was* a problem with DynamicProxy that didn't allow abstract methods but it was identified and fixed in 1.0.2 a looong time ago.

The thread below might shed some light on the matter for you but YMMV:

http://forum.hibernate.org/viewtopic.ph ... act+method

Cheers,

Symon.

_________________
Symon Rottem
http://blog.symbiotic-development.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 26, 2008 4:41 am 
Newbie

Joined: Fri Feb 15, 2008 12:13 pm
Posts: 15
merge_s.rottem wrote:
Without seeing your code it's a little hard to tell, but this sounds like your abstract method is probably not public.


you're right. there is one internal abstract method. declaring it public will fix the problem, too.
but i don't want hibernate to force me to open accessibility. so in this case, setting lazy to false is the better solution to me.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 26, 2008 7:14 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
If you read the thread I provided you you will see that Sergey offered a solution to that problem.

Symon.

_________________
Symon Rottem
http://blog.symbiotic-development.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 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.