-->
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.  [ 4 posts ] 
Author Message
 Post subject: Using a MAP to build a COMPONENT
PostPosted: Thu Dec 18, 2003 8:11 pm 
Beginner
Beginner

Joined: Wed Oct 01, 2003 3:47 pm
Posts: 44
Hello,

I've been staring at COMPONENT and MAP in the hibernate documentation hoping that the answer might come to me. I'm not having any luck and was hoping for some help. :)

The problem can be illustrated with a ONE-TO-MANY relationship between two tables:

Code:
[OBJECTS]
OBJECT_ID
TITLE

[OBJECT_PROPERTIES]
OBJECT_ID
PROPERTY_NAME
PROPERTY_VALUE


I understand that I can create a mapping for OBJECTS which includes a MAP to OBJECT_PROPERTIES (PROPERTY_NAME is the key, PROPERTY_VALUE is the element). Then I can access the key/value pairs from OBJECT_PROPERTIES as a map within OBJECTS.

But, I'd like to take this one step further and actually use the hibernate mapping to define the possible OBJECT_PROPERTIES. This has the benefit of using hibernate's excellent type conversion and custom types.

Therefore, what I want to do seems to me like a combination of MAP and COMPONENT. Except that I want to use the COMPONENT against the values of the map, NOT against physical columns in the database. That is, the COMPONENT would be built up using the key/value pairs in OBJECT_PROPERTIES as opposed to the key/value pairs of a physical database structure.

Any bright ideas on how this might be accomplished?

Thanks for your time,

Ryan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2003 8:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
<dynamic-component> ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2003 8:58 pm 
Beginner
Beginner

Joined: Wed Oct 01, 2003 3:47 pm
Posts: 44
Hi, thanks for the suggestion. I took a look at <dynamic-component>. I interpreted its use as:

"Map physical database columns to a hash, where there is a direct correspondence between columns/values of the database and keys/values of the map."

Is this a correct interpretation of <dynamic-component>? If so, this is somewhat the opposite of what I'm trying to do.

What I'm trying to do is: map the key/values built up using two columns of a table (OBJECT_PROPERTIES in the example above) to the actual methods of an object. For example, if the table OBJECT_PROPERTIES had the following rows:

Code:
OBJECT_ID, PROPERTY_NAME, PROPERTY_VALUE
1234, FIRST_NAME, Ryan
1234, LAST_NAME, Dewell


I want to map the row with the PROPERTY_NAME of "FIRST_NAME" to a method on OBJECT 1234 named getFirstName(), for example.

I understand the normal solution would be to simply add a column called FIRST_NAME to the OBJECTS table. :) But, OBJECTS will contain many different subclasses of OBJECT, all with very different OBJECT_PROPERTIES. Being able to map the name/value pairs from OBJECT_PROPERTIES to the different OBJECT subclasses is what we're trying to accomplish.

Any ideas?

Thanks again,

Ryan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2003 9:33 pm 
Beginner
Beginner

Joined: Wed Oct 01, 2003 3:47 pm
Posts: 44
To summarize, I guess what I need is a <component> that loads and persists its values like a <map>. A <map> can build its key/value pairs from the rows of a table, whereas a <component> can only formulate its key/value pairs from the physical structure of a database. A component would be perfect except for its reliance on the physical structure of the database.

Is there a way to write a custom component type that loads and persists values more like a <map>? I'm trying to combine the database flexibility of a <map>, with the typing/mapping functionality of a <component>.

Thanks,

Ryan


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