-->
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: What should be a basic polymorphic association question:
PostPosted: Fri Nov 13, 2009 3:26 pm 
Newbie

Joined: Tue Aug 11, 2009 11:38 am
Posts: 1
Ok, so I have the following objects:

Code:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
    name="behavior_type",
    discriminatorType=DiscriminatorType.STRING
)
@DiscriminatorValue("none")
public class BehaviorData implements BehaviorDataInfo{
...
}      


which is extended by four other classes, of which this is an example:

Code:
@Entity
@DiscriminatorValue("modifier")
public class CasualtyRateBehaviorData extends BehaviorData {
...
}


My problem is that I have another table, ShapeBehavior, where I include an enumerated type that tells me what kind of behavior we have. Then, I have a "BehaviorData" column that I want to be able to hold ANY of the behavior data inheritance tree of objects. (My java code uses the enum to tell what kind of data I have)

So, ShapeBehavior looks like this:

Code:
@Entity
public class ShapeBehavior implements ShapeBehaviorInfo {
...
   
   /**
    * The behavior associated with the Scenario Shape.
    */
   private SimBehavior simBehavior = SimBehavior.NONE;

   /**
    * Behavior Data Information, specific to the type of SimBehavior.
    */
   private BehaviorData behaviorData;
   
...

   @OneToOne(optional=true)
   public void setBehaviorData(BehaviorData newValue) {
      this.behaviorData = newValue;
   }

   public BehaviorData getBehaviorData() {
      return this.behaviorData;
   }
...
}


I get an error on deployment that the type of behaviorData cannot be determined. I've tried annotating it several ways. To reiterate: I want to be able to put either a BehaviorData object, or any of it's four subclasses into this variable, depending upon the setting of the behaviorType enum value. I've even tried using hte @Any annotation (which I only vaguely understand) like this:

Code:
    @Any( metaColumn = @Column( name = "behavior_type" ), fetch=FetchType.EAGER )
    @AnyMetaDef(
        idType = "integer",
        metaType = "string",
        metaValues = {
            @MetaValue( value = "none", targetEntity = BehaviorData.class ),
            @MetaValue( value = "modifier", targetEntity = CasualtyRateBehaviorData.class ),
            @MetaValue( value = "event", targetEntity = CasualtyEventBehaviorData.class ),
            @MetaValue( value = "avoid", targetEntity = TraversalAvoidBehaviorData.class ),
            @MetaValue( value = "prefer", targetEntity = TraversalPreferBehaviorData.class )
        } )



Any help will be greatly appreciated. Type slowly, I'm a Hibernate noob.


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.