-->
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.  [ 5 posts ] 
Author Message
 Post subject: Map keys of a java Map to a table
PostPosted: Sun Nov 07, 2010 1:24 pm 
Newbie

Joined: Sun Nov 07, 2010 1:13 pm
Posts: 2
Hi
I have a Map with keys where i wa to map the keys of themap as table columns,

So if Class Country has a map with Strings of cities as keys in the map i want a mapping when done reates a table with a name equivalent to Map reference with Map keys as table columns.

Can this be done. Please help urgent.


Top
 Profile  
 
 Post subject: Re: Map keys of a java Map to a table
PostPosted: Mon Nov 08, 2010 4:02 am 
Newbie

Joined: Thu Nov 01, 2007 1:43 pm
Posts: 5
Have you checked the hibernate reference documentation, there is section called as "Dynamic Models" where you will find an example.

The only thing what you need additional is a dynamic table creation, which i don't think hibernate will be able to do it. Alternatively you can write your own UserType implementations for customizing the way how a property of a bean is persisted and then retrieved back.

Let me know your comments on the same!


Top
 Profile  
 
 Post subject: Re: Map keys of a java Map to a table
PostPosted: Mon Nov 08, 2010 6:15 am 
Beginner
Beginner

Joined: Wed Jan 07, 2009 7:07 pm
Posts: 26
Are you trying to create dynamic tables based on your map column ? Can you elaborate your requirement which forces you to choose this design ?

Anyways you can use database store procedure for this and can call using named query.

Thanks
-Vishal


Top
 Profile  
 
 Post subject: Re: Map keys of a java Map to a table
PostPosted: Mon Nov 08, 2010 7:48 am 
Newbie

Joined: Sun Nov 07, 2010 1:13 pm
Posts: 2
HI

Thanks for the reply.

The motive behind this is our existing design.

Where ther is a class A that holds a map.

And A is associated with B where B has A.

So when B is updated/saved the Map field in A should be updated/saved as well. So that the Keys in the Map will be Table columns and values represent values per column.

And This map has a many-to-one with B. That is One of B can have many different Maps

Alternative suggestions are welcome.

Hope this is clear.

Thanks


Top
 Profile  
 
 Post subject: Re: Map keys of a java Map to a table
PostPosted: Mon Nov 08, 2010 9:53 am 
Beginner
Beginner

Joined: Wed Jan 07, 2009 7:07 pm
Posts: 26
Is your map expendable ? I mean are the columns fixed or u can increase the key value pair anytime.If its fixed then get rid off the map and move all properties in A and create a hbm for A.

If your legacy code usage the map and u can not avoid that then create the mapping of A with only a map.


Code:
<map name="properties">
            <key column="id"/>
            <index column="property_name" type="string"/>
            <element column="property_value" type="string"/>
        </map>



I am sorry if you have a dynamic map and you want to create a table with every save.

Thanks
-Vishal


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