-->
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.  [ 5 posts ] 
Author Message
 Post subject: Mapping one table to two different classes
PostPosted: Mon Mar 10, 2008 6:11 am 
Newbie

Joined: Mon Mar 10, 2008 3:05 am
Posts: 2
Location: India
Hi All,

I am in the process of migrating a piece of Java code to use Hibernate version 3.

I have a peculiar problem.


I want to map a table to two different classes for selected fields. i.e.


Code:
Table Name: Repair Table
-------------------------------
Job_Id
Job_date
Repair_Details

Class Name: JobCommon
-------------------------------
Job_Id
Job_Date

Class Name: Repair
----------------------------
Job_Id
Repair_Details


Both JobCommon and Repair class need to be mapped to the specific fields in table Repair as shown above.

Is it possible to do that in Hibernate? I have searched around and found that you can map 1 class to multiple tables but not vice-versa.

Please can anyone share some insights on how to approach this problem?

Thanks

_________________
-Suraj Berwal


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 10, 2008 6:48 am 
Newbie

Joined: Tue Feb 26, 2008 10:42 am
Posts: 5
Location: England
You will need to define or add a descriminator column in the table, and use the sub-class mapping.

http://www.hibernate.org/hib_docs/v3/reference/en/html/inheritance.html
This part of the documentation is applicable for you :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 10, 2008 7:06 am 
Newbie

Joined: Mon Mar 10, 2008 3:05 am
Posts: 2
Location: India
MattDavey wrote:
You will need to define or add a descriminator column in the table, and use the sub-class mapping.

http://www.hibernate.org/hib_docs/v3/reference/en/html/inheritance.html
This part of the documentation is applicable for you :)


Hello Matt,

The classes which I have described are not sub classes of each other but 2 concrete classes. I am not sure how sub-class inheritance can be applied here.

Please could you give me an example mapping? :-)

Thanks for your support!

Thanks,
Suraj

_________________
-Suraj Berwal


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 10, 2008 9:22 am 
Newbie

Joined: Tue Feb 26, 2008 10:42 am
Posts: 5
Location: England
Hello, I am sorry I misunderstood your first post.

I think, what you want to do is impossible with Hibernate. Perhaps a more experienced user can help you :)


Top
 Profile  
 
 Post subject: Re: Mapping one table to two different classes
PostPosted: Mon Mar 10, 2008 12:07 pm 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
You could create a common superclass and use the inheritance mapping.

Another idea would be to create views for each class and map to them instead of the table, but I am not sure if this works. Never worked with views and Hibernate.

_________________
Please rate useful posts.


Schauderhaft: Softwaredevelopment, Projectmanagement, Qualitymanagement and all things "schauderhaft"


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