-->
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: Unusual Inheritance mapping
PostPosted: Fri Jan 14, 2011 6:57 pm 
Newbie

Joined: Mon Jan 10, 2011 7:21 pm
Posts: 8
Hello,

I am trying to implement an unusual Inheritance mapping by which both super & subclasses are @Embedded in another @Entity. Let me explain with actual code:

I have a Request object:
Code:
@Entity
public class Request {
   …   
   …
   private DealType dealType;
   
   …
   …
   @Embedded
   public DealType getDealType() {
      return dealType;
   }
}


an abstract DealType superclass:

Code:
@Embeddable
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "DEAL_TYPE_DISCRIMINATOR", discriminatorType = DiscriminatorType.STRING)
public class DealType {
   
   private BigDecimal quotedAmount;

   public  DealType(){}

   protected DealType(BigDecimal quotedAmount) {
      this.quotedAmount = quotedAmount;
   }

   public BigDecimal getQuotedAmount() {
      return quotedAmount;
   }

   public void setQuotedAmount(BigDecimal quotedAmount) {
      this.quotedAmount = quotedAmount;
   }   
}


and a subclass UnitBasedDealType:

Code:
@Embeddable
@DiscriminatorValue("UNIT_BASED")
public class UnitBasedDealType extends DealType {

   private int numberOfUnits;
   
   public UnitBasedDealType(BigDecimal amount, int numberOfUnits) {
      super(amount);
      this.numberOfUnits = numberOfUnits;
   }

   public int getNumberOfUnits() {
      return numberOfUnits;
   }

   public void setNumberOfUnits(int numberOfUnits) {
      this.numberOfUnits = numberOfUnits;
   }
}


All properties of both DealType & UnitBasedDealType are defined inside the Request table.

When I try to save a UnitBasedDealType like this:
Code:

Request request = new Request();
request.setCreationDate(new Date());
request.setDealType(new UnitBasedDealType(new BigDecimal("44.55"), 4));
session.save(request);


the only properties that get saved are the DealType ones (which is the quotedAmount) and none of the UnitBasedDealType ones (which for this example is numberOfUnits).

Does anyone know if this type of mapping is possible with Hibernate?
Any thoughts?

I appreciate this might not be the best way to use Inheritance mapping but I'm working with a legacy schema.

Regards,
- Savvas


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.