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: Mapping classes with id as string
PostPosted: Thu Jul 07, 2011 5:48 am 
Newbie

Joined: Tue Jul 05, 2011 6:10 am
Posts: 4
The subject doesn't quite say it all but here goes. Some notes, I'm porting an existing project to hibernate so that I can easily extend support to different DBMS. I'm not an expert on database design but know a bit.

Code:
public abstract class AbstractDrugModel
{
    // Not null. Uniuqe.
    private String name = "";
    // Can be null.
    private IntravascularDrug ivDrug = null;
    // Not null
    private Equation outputEquation = null;
    // 0 or more.
    private List<DrugEvent> drugEvents = new LinkedList<DrugEvent>();
}

// Not the only subclass but sufficient for examples.
public class UserDefinedDrugModel
{
    // No properties.
}

public class IntravascularDrug
{
    // Some primitive properties.
    private int minimumInfusionTime = -1;
}

public class DrugEvent
{
    // The event name. Unique. Not null.
    private String eventName = "";
    // The index is important because it is used in other equations to reference this. Starts at 1.
    private int index = 0;
    // Other uninteresting properties.
}



Before hibernate:

I had a drug table to store the AbstractDrugModel. The primary key was the drug name which is unique and not null.

I had a DrugEvent table that stored the DugEvent properties. This had a foreign key to the drug name.

I had an IVDrug table that stored the IntravascularDrug instance if it existed. This had a foreign key to the drug name.

I had an OutputEquation table that contained the properties of the outputEquation and had a foreign key to the drug name.


From the design above I didn't need any of DrugEvent, IntravascularDrug or Equation to "contain" a reference to the AbstractDrugModel instance that owned it. I also didn't need any database identifiers for these as the drug name was suffient when storing in the database.

In my hibernate version I am using mapping files. I have used the drug name as the id field in the table for AbstractDrugModel. However I have not figured out with my original model how to use the drug name as a foreign key and this also as the the combined key with, for example, the drug event name.

In my current solution I've introduced an identifier to each of DrugEvent, IntravascularDrug and Equation. I've also added a reference in DrugEvent back to the AbstractDrugModel that owns it. I would prefer to avoid doing this, I'm open to suggestions however. I don't mind having DrugEvent reference back to AbstractDrugModel but the identifiers are not really needed.

In addition, my current mapping files now include in the table for the AbstractDrugModel table a column for the contained IntravascularDrug, as an example.

Here are some snippets:

Code:
  <class
    dynamic-insert="false"
    dynamic-update="false"
    lazy="false"
    mutable="true"
    name="tciworks.drugmodel.AbstractDrugModel"
    optimistic-lock="version"
    polymorphism="implicit"
    select-before-update="false"
    table="Drug">
    <list cascade="all-delete-orphan" name="eventList" table="DrugEvent">
      <key column="DrugName" not-null="true" update="false"/>
      <list-index column="EventIndex"/>
      <one-to-many class="tciworks.drugmodel.DrugEvent"/>
    </list>
    <many-to-one
      entity-name="OutputEquation"
      name="outputEquation"
      column="OutputEquationIdentifier"
      not-null="true"
      unique="true"
      lazy="false"
      cascade="all"/>
    <many-to-one
      name="intravascularDrug"
      column="IntravascularDrugIdentifier"
      not-null="false"
      cascade="all"
      unique="true"/>
</class>



The other mapping files don't mention the drug name, I'm not sure how to do this or if it can be done.

I hope this makes some sort of sense about what I'm trying to achieve. If not I will try to elaborate with one of the problems at a time.


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.