-->
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: Inheritance Single_Table problem
PostPosted: Tue Oct 27, 2009 7:03 am 
Newbie

Joined: Tue Oct 27, 2009 6:54 am
Posts: 2
Hello everybody,

Here is my config: a value table which has multiple inheritance

Code:
@Entity
@Table(name="Value")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "valueType", discriminatorType = DiscriminatorType.STRING)
public abstract class Value implements Serializable
{
   private static final long   serialVersionUID   = 7301755822929337372L;

   private long   id;

   @Id
   @GeneratedValue
   public long getId()
   {
      return id;
   }

   public void setId(long id)
   {
      this.id = id;
   }
}


parentId can be Characteristic or other class, so in CharacteristicMinValue and CharacteristicMaxValue, I configure the manyToOne association.

Code:
@Entity(name = "CharacteristicMinValue")
@DiscriminatorValue("CharacteristicMinValue")
public class CharacteristicMinValue extends CharacteristicValue implements Serializable
{
   private static final long   serialVersionUID   = 3167123861324562680L;

        @ManyToOne
   @JoinColumn(name = "parentId")
   public Characteristic getCharacteristic()
   {
      return characteristic;
   }

   public void setCharacteristic(Characteristic characteristic)
   {
      this.characteristic = characteristic;
   }
}


Code:
@Entity(name = "CharacteristicMaxValue")
@DiscriminatorValue("CharacteristicMaxValue")
public class CharacteristicMaxValue extends CharacteristicValue implements Serializable
{
   private static final long   serialVersionUID   = 3167123861324562680L;

        @ManyToOne
   @JoinColumn(name = "parentId")
   public Characteristic getCharacteristic()
   {
      return characteristic;
   }

   public void setCharacteristic(Characteristic characteristic)
   {
      this.characteristic = characteristic;
   }
}


Here is a class which have CharacteristicMaxValue:

Code:
@Entity
public class Characteristic extends CommonTable implements Serializable
{
   private static final long               serialVersionUID   = -4546790016363592545L;

   private List<CharacteristicMaxValue>      maxValue;

       @OneToMany(mappedBy = "characteristic", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
   @OrderBy("priority ASC")
   public List<CharacteristicMaxValue> getMaxValue()
   {
      return maxValue;
   }

   public void setMaxValue(List<CharacteristicMaxValue> maxValue)
   {
      this.maxValue = maxValue;
   }
}


the problem is:
when I load a characteristic object, all values for this object are loaded in MaxValues, the sql query does not take care of the discriminatorValue. What's the problem ?
(in my column valueType, the discriminator is well created when I add a CharacteristicMaxValue, but if I add to this Characteristic objects of type CharacteristicMinValue, there are added in maxValue...)

thanks


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.