-->
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.  [ 6 posts ] 
Author Message
 Post subject: Abstract Property
PostPosted: Thu Jan 12, 2006 8:25 am 
Newbie

Joined: Thu Jan 12, 2006 8:17 am
Posts: 8
Does anyone know how NHibernate deals with abstract properties?
This is what I mean:

Data (Abstract)
--------------------
int Id
string Name

Data1 : Data
---------------
DateTime StartDate
DateTime EndDate

Data2 : Data
----------------
string SerialNumber

Then imagine I have a class that has a property of type Data, since it sometimes need to have a Data1, and other times need to have Data2. The whole principle of inheriting.

How does NHibernate deals with this case, since typing Person.Data would give an error since Data is abstract and cannot be instantiated.

Thanks in advance,
Bernardo Heynemann


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 12, 2006 1:37 pm 
Newbie

Joined: Thu Jan 12, 2006 8:17 am
Posts: 8
Just helping clarify...

The Data Table would be like this:

Data
Id
Name
StartDate
EndDate
SerialNumber
DataType --- This is the attribute that differentiate between Data1 and Data2.

Thanks in advance,
Bernardo Heynemann


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 13, 2006 2:04 pm 
Newbie

Joined: Thu Jan 12, 2006 8:17 am
Posts: 8
Anyone? lol...

I´m in need of a solution for this issue (if it does have a solution...).

Thanks in advance,
Bernardo Heynemann


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 14, 2006 6:33 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
What do you mean by "how does NHibernate deal with this case"? It can deal with this in some cases, and not in others, so you have to specify what you are trying to do.

In general, polymorphic mapping is possible in NHibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 15, 2006 9:53 pm 
Newbie

Joined: Thu Jan 12, 2006 8:17 am
Posts: 8
Sorry if i was vague.
I´m the lead architect in my company and I want to use nhibernate as our ORM, but I´m curious about two things:
1 - If it can do the above mapping.
2 - How does it do it? (This I want to know as a developer since I couldn´t think of a viable solution for it and it really annoyed me)

Thanks in advance,
Bernardo Heynemann


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 15, 2006 10:00 pm 
Regular
Regular

Joined: Mon May 16, 2005 1:35 am
Posts: 67
I think you're looking for the table-per-class-hierachy mapping strategy. Define the mapping for your abstract base class Data, and then use the <subclass> tag to define the mapping for each derived class.

Use the discriminator-value attribute to specify which class maps to which value of the DataType field. Specify a value for the Data abstract class discriminator-value that will never appear in the database (e.g. null). This way, NHibernate will never attempt to instantiate an instance of your abstract base class.


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