-->
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.  [ 4 posts ] 
Author Message
 Post subject: Determine type of abstract class returned from NHibernate
PostPosted: Fri Mar 30, 2007 12:13 pm 
Beginner
Beginner

Joined: Wed Nov 29, 2006 12:23 pm
Posts: 42
I have an abstract class which has two concrete implementations.

I need to be able to retrieve the abstract class because users will only provide an id/code, which is not type specific, however in my service layer (above business layer), I need to be able to determine the type of the abstract class so that I can carry out some conditional logic.

Is there any other way to determine the type of the class, apart from using NHibernate.NHibernateUtil.GetClass()?

The type of the entity at this point when I call GetType is always the abstract type, even though intellisense within the IDE displays the proper concrete type.

well, actually, in some instances it does return the correct type, and other instances it doesn't.

I also find that in some instances I'm able to cast the abstract type to the concrete type, and other times I'm unable to. I can see that the SQL issued for the select includes all of the attributes defined on the concrete implementations.

I'd prefer not to have to let my service layer know about NHibernate.


Top
 Profile  
 
 Post subject: Re: Determine type of abstract class returned from NHibernat
PostPosted: Fri Mar 30, 2007 12:22 pm 
Beginner
Beginner

Joined: Wed Jun 28, 2006 2:03 pm
Posts: 22
hitch wrote:
I have an abstract class which has two concrete implementations.

I need to be able to retrieve the abstract class because users will only provide an id/code, which is not type specific, however in my service layer (above business layer), I need to be able to determine the type of the abstract class so that I can carry out some conditional logic.

Is there any other way to determine the type of the class, apart from using NHibernate.NHibernateUtil.GetClass()?

The type of the entity at this point when I call GetType is always the abstract type, even though intellisense within the IDE displays the proper concrete type.

well, actually, in some instances it does return the correct type, and other instances it doesn't.

I'd prefer not to have to let my service layer know about NHibernate...


I think you need something like that:
Code:
if (object.GetType().Equals(typeof(MyClass)))
{

}



cya


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 02, 2007 3:45 am 
Beginner
Beginner

Joined: Wed Nov 29, 2006 12:23 pm
Posts: 42
as mentioned in my post, GetType doesn't return what I'm after.

Anyone?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 02, 2007 4:36 am 
Beginner
Beginner

Joined: Wed Nov 29, 2006 12:23 pm
Posts: 42
I'm using the method found here

http://forum.hibernate.org/viewtopic.php?t=959834

in my DAO for the time being, to cast the INHibernateProxy to it's concrete type, but still returned as it's abstract type, and then in my service layer I can reliably say

Code:
if (entity is ConcreteA)
{

}
else
{

}


but I'm open to other suggestions!


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