Hello,
I used to have something likes this :
A
Code:
Person
has a
Code:
Name
and an
Code:
Address
...
So i create mappings for a person, name and address.
But I would like to use a generic Object (TransferObject).
This TransferObject holds a map with it's properties.
To give an example for an Address :
Address is an empty class that simple extends my TransferObject.
Code:
public abstract class TransferObject {
public static final String UNKNOWN_ID = "-1";
private String id = UNKNOWN_ID ;
private Map properties ;
public TransferObject() {
properties = new HashMap(25);
}
public String getId() {
return id ;
}
public void setId(String id) {
this.id = id ;
}
public void setProperty(String key, Object property) {
getProperties().put(key, property);
}
public Object getProperty(String key) {
getProperties().get(key);
}
public Map getProperties() {
return properties ;
}
}
public class Address extends TransferObject {
}
So far i made my TransferObject abstract and Address, Name and Person are empty classes that simply extend TransferObject. I made a custom PropertyAccessor for Hibernate to work with the map.
And everything works fine! (A big thanks to the Hibernate team to make this possible ! ;-))
Next step would be that i don't want to use the empty subclasses, but i want to keep using my existing mapping.
So i am thinking of adding a type field in my TransefObject class. But is there any way to make a conversion for the value of that type to the actual mapping Hibernate takes.
Again an example :
if the field type = "mypackage.Address" in my TransferObject.
Can i make Hibernate to take the mapping that corresponds with class="mypackage.Address" ?
And if i can do that, the following question will be : how ?
Hopefully someone can help me on this.
Thanks,
Davy.