-->
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: Dynamic mapping to plain object model
PostPosted: Wed Apr 14, 2004 9:29 am 
Newbie

Joined: Fri Apr 02, 2004 9:18 am
Posts: 5
Location: Cologne, Germany
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.


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.