-->
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.  [ 7 posts ] 
Author Message
 Post subject: Using internal methods on domain objects
PostPosted: Fri Apr 28, 2006 11:10 am 
Beginner
Beginner

Joined: Mon Dec 19, 2005 4:13 am
Posts: 27
Location: Prague, Czech Republic
Hi,

I have found a problem with accessing a collections in lazy persistent objects from methods marked as internal. The collections are not initialized and they are not either associated with Nhibernate (they do not implement IPersistentCollection interface). For example, I get zero as result of Count proprty on collection that contains many items when it is accessed from internal method.

As required, all my public and protected methods and properties are marked as virtual, and the same is true for my internal methods. As far as I can understand, NHibernate overrides these method and properties.

My question is, if the fact that internal methods are not overrided is feature by design because it simply is not possible or it can be done in some way and I found a bug? :-)

Many thanks for answer.
David


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 3:25 am 
Beginner
Beginner

Joined: Mon Dec 19, 2005 4:13 am
Posts: 27
Location: Prague, Czech Republic
Please,

can someone post me which method of NHibernate I can use from my internal method to give NHibernate know to initialize an object?

Thanks David


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 3:37 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
sousek wrote:
can someone post me which method of NHibernate I can use from my internal method to give NHibernate know to initialize an object?


Write an public virtual empty method called "ForceInitialization" (or smth)?

Gert


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 4:11 am 
Beginner
Beginner

Joined: Mon Dec 19, 2005 4:13 am
Posts: 27
Location: Prague, Czech Republic
Yes. I did it, but it did not help. I cannot uderstand why :-).


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 5:21 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
DynamicProxy probably can't override internal methods because .NET doesn't allow it to. You can force initialization of a proxy using NHibernateUtil.Initialize(proxy).


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 9:05 am 
Beginner
Beginner

Joined: Mon Dec 19, 2005 4:13 am
Posts: 27
Location: Prague, Czech Republic
Many thanks, Sergey.

Please can you briefly explain me why it does not help to call empty public virtual method (called "Ping" or "Initialize") on domain object from the internal method to force initialization? Is NHibernate monitoring if the call is done outside of object or it has another reason?

Thanks again.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 12:45 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
When a proxy is initialized, a new object of that type is created, so for a proxied class A you actually end up with two objects: the proxy, of class ProxyA (derived from A and overriding its virtual methods), and the real object of class A. This implementation leads to these kinds of interesting side effects.


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