-->
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.  [ 2 posts ] 
Author Message
 Post subject: Mapping Question
PostPosted: Tue Sep 12, 2006 11:32 am 
Beginner
Beginner

Joined: Tue Oct 26, 2004 4:59 pm
Posts: 23
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 10:34 am 
Beginner
Beginner

Joined: Tue Oct 26, 2004 4:59 pm
Posts: 23
Gee, thanks for all the responses.

We ended up revisiting the ResourceMaterial class hierarchy and made modifications.

Karl


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.