-->
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.  [ 6 posts ] 
Author Message
 Post subject: Interesting mapping question
PostPosted: Tue Oct 25, 2005 5:10 pm 
Newbie

Joined: Fri Jun 24, 2005 10:40 am
Posts: 17
I have an interesting situation and I am looking for ideas on how to map it. This is complicated so please bear with me. We are creating a unit and scale api in which the unit and scale are concrete classes derived from the base class. For example:

BaseScale:

import java.io.Serializable;

public class BaseScale implements IScale,Serializable {

/**
* Field serialVersionUID
*/
private static final long serialVersionUID = 7379777895752566495L;

protected String name;

protected String shortName;

protected String longName;

protected String abbreviation;

/**
* Accepts the dimension and name as a parameter
* @param dimension
* @param name
*/
protected BaseScale(String aName,String aShortName, String aLongName, String anAbbreviation) {
name = aName;
shortName = aShortName;
longName = aLongName;
abbreviation = anAbbreviation;
}

/**
* @see net.hcsc.util.scale.IScale#getShortName()
*/
public String getShortName() {
return shortName;
}

/**
* @see net.hcsc.util.scale.IScale#getLongName()
*/
public String getLongName() {
return longName;
}

/**
* @see net.hcsc.util.scale.IScale#getAbbreviation()
*/
public String getAbbreviation() {
return abbreviation;
}

/**
* @return Returns the name.
*/
public String getName() {
return name;
}

/**
* Method hashCode
* @return int
*/
public int hashCode() {
return name.hashCode() + shortName.hashCode() + longName.hashCode() + abbreviation.hashCode();
}

/**
* Method equals
* @param other Object
* @return boolean
*/
public boolean equals(Object other) {
return (other instanceof BaseScale) && equals((BaseScale)other);
}

/**
* Method equals
* @param other Scale
* @return boolean
*/
public boolean equals(BaseScale other) {
if(other == null) {
return false;
}
if(other == this) {
return true;
}

return (name == other.getName()) && (longName == other.getLongName()) && (shortName == other.getShortName()) && (abbreviation == other.getAbbreviation()) ;
}

/**
* TODO - Describe the method
* @param abbreviation The abbreviation to set.
*/
public void setAbbreviation(String abbreviation) {
this.abbreviation = abbreviation;
}

/**
* TODO - Describe the method
* @param longName The longName to set.
*/
public void setLongName(String longName) {
this.longName = longName;
}

/**
* TODO - Describe the method
* @param name The name to set.
*/
public void setName(String name) {
this.name = name;
}

/**
* TODO - Describe the method
* @param shortName The shortName to set.
*/
public void setShortName(String shortName) {
this.shortName = shortName;
}

}


Millions:

import java.io.Serializable;

public class Millions extends BaseScale implements Serializable {

/**
* Field serialVersionUID TODO describe the field
*/
private static final long serialVersionUID = -6360556925659098520L;

/*static {
name = "Millions";
shortName = "Mil";
longName = "Millions";
abbreviation = "M";
}*/

/**
* TODO Describe the constuctor
*/
public Millions() {
super("Millions","Mil","Millions","M");
}

}

In our application we would like a table of unit and of scales so we can point an object to one row of the table (one to many relationship from scale to object). The trick is that since these are util classes, I do not want to include an id in the class. So, I created a wrapper to contian the id. the problem is how to map the inheritance from BaseScale to the concrete classes since they are a component of the wrapper class.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 12:21 pm 
Beginner
Beginner

Joined: Thu Sep 15, 2005 4:16 pm
Posts: 29
Aren't you just describing a component? A component is mapped from one or more columns as part of another entity. Look here:
http://www.hibernate.org/hib_docs/v3/reference/en/html/components.html#components-dependentobject
at the discussion of components.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 12:33 pm 
Newbie

Joined: Fri Jun 24, 2005 10:40 am
Posts: 17
Yes that is true. But in the case the component is a polymorphic situation since I am just bpassing the base class instead of the concrete class. Since that is the case, how will hibernate know to cast this as an instance of Millions instead of BaseScale. All Polymorphic examples deal with an association and not a component.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 12:47 pm 
Beginner
Beginner

Joined: Thu Sep 15, 2005 4:16 pm
Posts: 29
Perhaps I don't understand. I would think that for your case, any particular table that is using this will be mapping a specific BaseScale subclass. If you really needed to be polymorphic here I think your only option would be to create a class for the mapping that could return the specific component represented, i.e. a kind of Facade object.

As a related example, you could have a Currency object that maps to two columns. One column provides the number of pennies, pence, etc. in a particular currency and the other provides a type such as euro, dollar or pound. Then Currency could have a getMoney() method that returns a subclass (of Currency or another hierarchy) such as Dollar, Euro, Pound.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 1:57 pm 
Newbie

Joined: Fri Jun 24, 2005 10:40 am
Posts: 17
Thanks for the help. I may need to rethink this.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 2:09 pm 
Newbie

Joined: Fri Jun 24, 2005 10:40 am
Posts: 17
This has become bigger than I wanted it to be. I have been charged with creating a generic API for handling units and scale. Each unit would be a conrete class that belongs to some dimension(i.e. Time is the dimension and Minute is the unit) each unit would know how to convert from other usits and perfom mathmatical functions with itself and other units as well as know how to format the value it is applied to(i.e. if 1000 was applied to a dollars unit it would be $1000.00). There is a similar construct to in which the concrete classes would almost be types for a given scale. So millions would be the scale and it would know its titles, abbreviations etc. So I took a stab at it and now must incorporate it into the application since this is a generic API, I have been told that hibernate cannot effect those classes so I created a wrapper that would contain an id an an incstance of the base class. So I am thinking I may need to look at my unit scale API from another direction.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.