-->
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.  [ 1 post ] 
Author Message
 Post subject: Table per class hierarchy mapping considering polymorphism
PostPosted: Mon Oct 17, 2011 8:14 pm 
Newbie

Joined: Sat Jan 29, 2011 8:36 am
Posts: 3
This is an example Table Per Class Hierarchy mapping:

Payment - Base (SuperType)
Code:
@Entity
@Table(name = "PAYMENT")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn( name = "type", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("BASE") 

public class Payment { 
private Product product; 
private Date date;
private Customer Customer; 
getters/setters
}
CreditCard
Code:
@Entity
@DiscriminatorValue("CC")
public class CreditCard extends Payment {   
private String Account   
getters/setters
}
Cash
Code:
@DiscriminatorValue("CASH")
public class Cash extends Payment {   
private String Paper 
private String Coins   
getters/setters 
}
Hibernate is able to accept an instancce of Payment, or Credit or Cash referenced as the Payment type and persist the correct instance thru some really complex code I traced through. What an exercise that was. :-)

My question is centered around working with the Payment instance polymorhically in my code . I would like to reference Payment anytime but each subclass adds unique instance fields so i lose those methods when working with a Payment reference. I could stub out these subclass fields on Payment itself to gain the benefit of polymorphism, but I don't think this is the correct way. I can also add a bunch of if/thens to create concrete instances and then work with those, but again does not seem like the right way to do things. I suspect either that my mapping is incorrect or I need to re-work my code. The table per class hierarchy mapping seems very clean and logical and would like to keep it, but not at the cost of fighting it elsewhere.
Thanks
-J


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.