-->
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: How can I do a Mapping map<String,Object>
PostPosted: Mon Apr 14, 2008 3:13 am 
Newbie

Joined: Thu Mar 27, 2008 9:28 am
Posts: 9
Hi,

I want to create a mapping for map<String,Object> in XML.

Is what somebody has an idea?

Thank you

jerome


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 14, 2008 8:52 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
If I am right, you want to use Map instead of java classes(POJOs) for persistence.
You can do it making few changes to your hibernate configuration and mapping files.

Configuration
By default hibernate works for POJO mode. Add the following entry in your configuration file to make it wok with maps.

Code:
hibernate.default_entity_mode = dynamic-map


Changes to be made in your mapping file

Use "entity-name" instead of or addition to "name" in the class tag
Example
Code:
<class entity-name="employee">
...
</class>


instead of

Code:
<class name="Employee">
...
</class>


You can use entity-name for relationships also to work with map of maps.

_________________
Sukirtha


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 14, 2008 9:30 am 
Newbie

Joined: Thu Mar 27, 2008 9:28 am
Posts: 9
Thanks for the answer but I was not pretty clear.

In fact I have a class with some fields and I want to do a mapping of this class.
One of these fields is :
Code:
private map<String,Object> parameter


I have try with the following code:
Code:
<map name="Parameter"
            table="PARAMETER">
           <key column="id" not-null="true"/>
           <map-key column="name" type="string"/>
           <element column="name_S" type="object"/>
      </map>


But type="object" is not exist.

If someone at an idea...

Thanks

jerome


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 14, 2008 10:20 am 
Beginner
Beginner

Joined: Wed Mar 05, 2008 4:57 am
Posts: 22
Location: Bangalore,India
Map<String,Object> is one type of using Map Collection.

Map<Object,Object> and Map<String,String> are others to mention.


<map name="Parameter" table="PARAMETER">
<key column="id" not-null="true"/>
<index column="index_id" type="String"/>
<many-to-many column="value_id" class="Specify the Object Class Type here"/>
</map>

The above mapping makes use of :
String as Key of Map.
Object which can be reused hence <many-to-many>, as Value of Map.

This mapping will make use of a table called PARAMETER with 3 columns :

id index_id value_id
== ====== ========

a) id would be the foreign key to the primary key (most probably) of the class for which this Map is an instance variable.
b) index_id would be the value of the key of the map.
c) value_id would be the foreign key to the primary key of the instances of the class that would behave as Value of the Map.

_________________
Naresh Waswani
+91-9986461501


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.