I'm trying to map a simple domain model to a possible more or less complex table layout with hibernate 2.1:
The domain model is simple:
Code:
FeatureType <---typeOf--- Feature ---has---> FeatureProperty
| /\
| | parent
+-has-+
Only instances of
Feature and their attributes
FeatureProperty are persistent. The reference between Feature and FeatureType is handled programmatically by the application. The class Feature is implemented as follows:
Code:
public class Feature implements Serializable {
private String id;
private Map attributes = new HashMap();
public String getId() { return this.id;}
protected void setId(String newId) { this.id = newId; }
public FeatureProperty getProperty(Object name) { return (FeatureProperty) this.attributes.get(name); }
public void setProperty(Object name, FeatureProperty value) { this.attributes.put(name, value); }
}
And the
FeatureProperty class:
Code:
public class FeatureProperty implements Serializable {
private String name;
private Object value;
// and the getter and setter for name and value
}
At runtime this classes should be mapped to a table layout like this for example:
Code:
City
--------
id varchar(16) (P.K)
name varchar2(50)
status varchar2(50)
population double(15)
country varchar(16)(FK)
Country
---------
id varchar(16) (P.K)
name varchar2(100)
area double(15)
population double(15)
So, 3 questions arise:
* How can the columns be mapped to the Map of FeaturePropeties for each Feature (e.g. Feature=City with attributes name,status,population,...)?
* And is Hibernate capable to deal with 2 instances of the same class but mapped to different tables where the primary keys could be equal?
* Does this make sense at all, or is the prefered way to generate JavaBeans for each table?
Thanx for any help.