-->
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.  [ 8 posts ] 
Author Message
 Post subject: Multiple Tables to One Class.
PostPosted: Tue Jan 17, 2006 7:14 am 
Beginner
Beginner

Joined: Mon Jan 09, 2006 8:02 am
Posts: 22
Hi,
Is it necessaryto have one HBM.XML file for each class. In my DB design there are a lot of One-to-One relationship. So is there any way Can i have one class Mapped to Different Tables.....
If yes Can anyone give me a small examle how will the HBM.XML file look like

Thankz

Help will be rewarded by Positive Ratings :-)


Top
 Profile  
 
 Post subject: Can you explain a bit more
PostPosted: Tue Jan 17, 2006 7:39 am 
Regular
Regular

Joined: Tue Jan 03, 2006 7:21 am
Posts: 85
Can you explain a bit more as to what you want to achieve.

I do not think you can map a class to more than one table using NHibernate (I may be wrong as I too am a new user). One way to do this would be to define a view first and then map the view.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 9:06 am 
Regular
Regular

Joined: Mon Jul 18, 2005 4:10 am
Posts: 92
Location: Poland
I'm guessing you may need joined-subclass

http://www.hibernate.org/hib_docs/reference/en/html/mapping.html#mapping-declaration-joinedsubclass

if not, what you need is to clarify your question ;) ....

_________________
michal


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 18, 2006 8:11 am 
Beginner
Beginner

Joined: Mon Jan 09, 2006 8:02 am
Posts: 22
Let me explain my Problem more in detail: Assuming we hav 2 Tables with a One to One Mapping

Table Name: Customer_Details.
Customer_id(PK)
Customer_name

2nd table: Customer Address
Customer_id(PK+FK)
Customer_address

Now i want a class Customer as

Class Customer
{
string Customer_id;
string Customer_name;
string Customer_address
}

Now is there a way This can be implemented. ????

Regards

Prasanth


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 18, 2006 8:37 am 
Regular
Regular

Joined: Mon Jul 18, 2005 4:10 am
Posts: 92
Location: Poland
As far I know , the only way to use one mapping with severall classes is to use component mapping - but it requires to have all columns in one table (see the docs)

In my opinion , for your case it is the best to implement addional class for the address and map it as ordinary one-to-one with id generator set as "foreign":

Class Customer
{
string Customer_id;
string Customer_name;
Address Customer_address
}

Class Address
{
string the_address
}

here is doc about one-to-one (look for generator class="foreign" phase) : http://www.hibernate.org/hib_docs/reference/en/html/mapping.html#mapping-declaration-onetoone


And finally - if you don't like many hbm.xml files (each for every class) - why not to put some <class> elements in one <hibernate-mapping> :) ? (not recommended approach btw)

_________________
michal


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 19, 2006 10:38 pm 
Regular
Regular

Joined: Mon May 16, 2005 1:35 am
Posts: 67
The feature you are after is available in Hibernate 3 and has not yet been ported to NHibernate. It uses the <join> element in the class mapping file.

The best way to achieve this with NHibernate as it currently stands is using the joined-subclass mapping. Create a CustomerBase class (abstract) which maps to the Customer table, and then your Customer class inherits from CustomerBase adding the Address property, and is mapped using joined-subclass.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 12:04 am 
Beginner
Beginner

Joined: Mon Jan 09, 2006 8:02 am
Posts: 22
Thankz.....


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 5:32 pm 
Beginner
Beginner

Joined: Wed Oct 05, 2005 5:35 am
Posts: 47
Location: France
I've submited a request for this:
http://jira.nhibernate.org/browse/NH-466...
Vote for it in Jira if you need it


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