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.