-->
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.  [ 3 posts ] 
Author Message
 Post subject: Is it possible to map on a field instead of a class ?
PostPosted: Mon Dec 15, 2003 11:18 am 
Newbie

Joined: Mon Dec 15, 2003 10:50 am
Posts: 1
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.


Top
 Profile  
 
 Post subject: RE: it possible to map on a field instead of a class ?
PostPosted: Thu Mar 04, 2004 8:23 am 
Newbie

Joined: Fri Feb 27, 2004 9:25 am
Posts: 8
I am currently trying to do something similar, and would be interested in how the custom PropertyAccessor looks like.

It would be great with some help, I am trying to figure out how a workaround to get dynamic-insert/update to work when using properties within a dynamic-component.

Regards

_________________
Kristofer


Top
 Profile  
 
 Post subject: RE: it possible to map on a field instead of a class ?
PostPosted: Thu Mar 04, 2004 8:42 am 
Newbie

Joined: Fri Feb 27, 2004 9:25 am
Posts: 8
Or as a matter of fact, what would be interesting to see is the custom getter/setters.

Regards

_________________
Kristofer


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