-->
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.  [ 2 posts ] 
Author Message
 Post subject: Multiple Table mapping to Same Java Class
PostPosted: Mon Mar 05, 2007 7:38 pm 
Beginner
Beginner

Joined: Thu Mar 01, 2007 9:40 am
Posts: 23
Location: UK
Hi,

I am new to Hibernate, and would like to know how a java model class can be mapped to different database tables in Hibernate.

I have the following scenario:
I have a java class A, which is used in different contexts as below.
In certain cases, A will appear as aggregation composition to class B.
i.e., B -> A*
and in certain cases, A will appear as aggregation composition to class C.
i.e., C -> A*

In this case, I have a set of A objects under B and a set of different A objects under B as well.

As I understand from Hibernate Tutorials, I need to have a OR mapping from A to a Database Table, B to a DB table, and C to a DB table. Hence I'll have to create DB mapping as below:
A -> TABLE_A
B -> TABLE_B
C -> TABLE_C

But this is not what I want, as this breaks my business model of tables.
I would like the information to be stored in the following tables;
B -> TABLE_B
C -> TABLE_C

A that's aggregated under B class should be stored in TABLE_A1
and A that's aggregated under C class should be stored in TABLE_A2

Can you let me know if it's possible to specify this mapping through Hibernate?

I really appreciate any response.

Thanks
--
Anish.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 06, 2007 5:39 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
You could map A as a component.

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


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