Getting implementation of proxy fails - how to avoid this

13 views
Skip to first unread message

Pavol Drozd

unread,
May 24, 2022, 3:15:45 PM5/24/22
to nhusers
Hi all, I am trying to check the proxy object and its persister info. 
However in some cases I am not able to analyze the entity since its uninitialized and not sure how to avoid exceptions, for more info see example: 
 var isProxy= objectToCheck.IsProxy();
                if ( isProxy  )
                {
                    ILazyInitializer li = ((INHibernateProxy)objectToCheck).HibernateLazyInitializer;
                    var tmp = li.GetImplementation();
                 }

Problem is that in some proxies - there is no target, so no such implementation exists - based on that, I am not able to get persister/entity entry to check some additional info. 
Is there better way, than silently catching "ObjectNotFoundException: No row with the given identifier exists" exception to avoid this ? Is there any way, how can I detect these uninitialized proxy ? 
I tried some things like checking persistent context entity entries key list or using IsUninitialized property - but this is always false for each entity etc. 

Thanks in advance. 

Br. Palo 

Reply all
Reply to author
Forward
0 new messages