Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 2.1.8
I am having some difficulty figuring out how to map this hierarchy. Here are my objects:
Code:
public abstract class ResourceMaterialImpl implements ResourceMaterial {
protected Calendar creationTimestamp;
protected String creationUserId;
protected String name;
protected String description;
protected String type;
protected int version = -1;
}
class ConstructionMaterialImpl extends ResourceMaterialImpl implements ConstructionMaterial {
private ImmutableMeasuredValue recycleContent;
protected ConstructionMaterialImpl(String code) {
super(code);
}
public ImmutableMeasuredValue getRecycleContent() {
return recycleContent;
}
public void setRecycleContent(ImmutableMeasuredValue recycleContent) {
this.recycleContent = recycleContent;
}
}
class LinerMaterialImpl extends ResourceMaterialImpl implements LinerMaterial {
protected LinerMaterialImpl(String code) {
super(code);
}
}
So far I have a ResourceMaterial class with subclasses ConstructionMaterial and LinerMaterial. ConstructionMaterial adds a new property called recycleContent.
Here are some more objects:
Code:
public abstract class PackageSpecificationImpl implements PackageSpecification {
// Members common to all package specs
protected String description;
protected ConstructionMaterial primaryMaterial;
protected ImmutableMeasuredValue weight;
protected PackageCategory packageCategory;
protected int version = -1;
// Member specific to a CanImpl
protected ConstructionMaterial secondaryMaterial;
protected LinerMaterial linerMaterial;
}
public class CanImpl extends PackageSpecificationImpl implements Can {
public ConstructionMaterial getSecondaryMaterial() {
return secondaryMaterial;
}
public void setSecondaryMaterial(ConstructionMaterial secondaryMaterial) {
this.secondaryMaterial = secondaryMaterial;
}
public LinerMaterial getLinerMaterial() {
return linerMaterial;
}
public void setLinerMaterial(LinerMaterial linerMaterial) {
this.linerMaterial = linerMaterial;
}
}
Here is the table structure:
MATERIAL TABLE
MAT_CD
DESCRIPTION
MAT_TYPE (Discriminator field that determines if this is a LinerMaterial or ConstructionMaterial
VERSION_NO
PACKAGE_SPEC
PART_NO
DESCRIPTION
PRIMARY_MAT_CD
PRIMARY_MAT_RECYCLE_CONTENT_VAL
PRIMARY_MAT_RECYCLE_CONTENT_UOM
SECONDARY_MAT_CD
SECONDARY_RECYCLE_CONTENT_VAL
SECONDARY_RECYCLE_CONTENT_UOM
LINER_MAT_CD
Ok. We are using type 1 inheritance, one table per hierarchy. Also, the type ImmutableMeasuredValue is a custom type that consists of a BigDecimal value and a unitOfMeasure of type UnitOfMeasure. The purpose of the class mainly is to allow conversion between different units of measure, and sorting by conceptual value, meaning 3 quarts will sort before 1 gallon, which will sort before 5 quarts. But that's not really important here.
What is stumping me is that in the objects, recycle content is with the object, but in the database it has been separated into another table. What I'm not getting is when I am mapping the ResourceMaterialImpl class and the subclass ConstructionMaterialImpl, I don't know what to do with the recycleContent.
Thanks,
Karl