-->
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.  [ 3 posts ] 
Author Message
 Post subject: Downcast User -> Partner HELPMEPLEASE!!!
PostPosted: Sat Jul 14, 2007 3:46 am 
Newbie

Joined: Mon Mar 05, 2007 9:04 am
Posts: 6
Location: Belarus
Hello all,

I've got a simple (I think) problem. But I'm stuck with it.

I have two classes (very simplified):

Code:
class User {
    Long id;
    String username;
    ...
}

class Partner extends User {
    String country;
}


Partner is mapped as joined-subclass of User. Table per concrete class. Tables tb_users and tb_partners are joined by primary keys (user id).

Now i want to promote existent User to Partner. Please, any tips.

UPD: tips like "you are using OOP in a wrong way" are also accepted !!!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 14, 2007 12:51 pm 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
Instead of Partner extending User, I'd put the User object inside the Partner and store each in their own unrelated tables. Creating a Partner from an existing user then becomes trivial.

Use a one-to-one mapping Partner->User and, optionally, from User->Partner. Having it bi-directional allows you to query for Users matching some criteria on Partner. You don't need to expose the Partner property from User if you don't want to - hibernate can access private get/set methods.

If you need to mix User and Partner objects for some operations then extract an interface from User and make User and Partner implement. To implement the new interface in Partner, delegate the methods to the contained User object.

Mike


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 3:44 am 
Newbie

Joined: Mon Mar 05, 2007 9:04 am
Posts: 6
Location: Belarus
thanks Mike! solved!


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