-->
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: 1 POJO - M tables ?
PostPosted: Wed Mar 08, 2006 4:27 am 
Regular
Regular

Joined: Wed Mar 08, 2006 2:07 am
Posts: 50
Location: Bangalore
This is just a general query, regarding whether this can be done or not ?

My question is Can a POJO class be created that can refer to different tables at different times.

Eg object of class "Address" which can refer to "PersonAddress" (table) when an object of "Address" type is stored in "Person" class (a table also exists by the name Person ), and when an "Address" reference is stored in say "Organization" class (a table also exists by that name) then it has data from "OrganizationAddress" table.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 8:02 am 
Beginner
Beginner

Joined: Wed Jan 25, 2006 10:16 am
Posts: 44
Location: Bangalore
Hai.
I would really like to help you. but if you can please rephrase your last two lines, I'd be happy. I cannot understand. Sorry for the trouble.
:-)

_________________
Please vote if my Postings helps. :-)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 8:43 am 
Regular
Regular

Joined: Wed Mar 08, 2006 2:07 am
Posts: 50
Location: Bangalore
Ok to make that even simpler...

There is a class named Address { String line1,line2,city,state;}

Now i also have a POJO named Person and Organization.
Person and Organization can both have multiple addresses just like you can have many residences and the way my company has many offices :-)
The Person class has a reference of Address type in it

Code:
class Person
{
     Address myAddress[];
     ......
}


Code:
class Organization
{
    Address orgAddress[];
    ......
}


All addresses related to Person are stored in table PersonAddress and addresses related to Organization are stored in table OrganizationAddress.
Both PersonAddress and OrganizationAddresses store same columns.

So is it possible that I use only 1 datatype of Address POJO instead of using two seperate Hibernate POJO's for PersonAddress and OrganizationAddress ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 8:48 am 
Beginner
Beginner

Joined: Fri Oct 28, 2005 7:11 am
Posts: 20
use inheritance with 'table per class' strategy.
a) base class: address, the rest inhertis from them.
b) and as you want two DB tables, choose 'table per class'


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 9:17 am 
Regular
Regular

Joined: Wed Mar 08, 2006 2:07 am
Posts: 50
Location: Bangalore
i will try that ... i think that would work ...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 9:18 am 
Beginner
Beginner

Joined: Wed Jan 25, 2006 10:16 am
Posts: 44
Location: Bangalore
Exactly.
Do as 'tbech ' suggested.

try using this clause "<joined-subclass>". :-)

_________________
Please vote if my Postings helps. :-)


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.