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: Need a Update query where the source is a Hashmap
PostPosted: Sat May 17, 2008 7:50 am 
Newbie

Joined: Sat May 17, 2008 5:22 am
Posts: 8
I am new to Hibernate. I have a doubt.
I have a HashMap with a (Key,Value ) pair like this
Key Value
1 A
2 B
3 C

And i have a table like this

Table :
------------------------
Id Value
1 null
2 null
3 null
1 null
2 null
3 null

I want to write an update query to update the table with the values of the HashMap. Can anyone suggest how should my update query look like using java code.

At the End my table should look like this
Id Value
1 A
2 B
3 C
1 A
2 B
3 C


Please anyone help me ? :-)


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 17, 2008 9:58 am 
Beginner
Beginner

Joined: Wed Dec 20, 2006 11:21 am
Posts: 20
First your HashMap should be stored on a persistent class (eg, a class mapped to Hibernate). Then you just save one instance of that class, containing your desired HashMap.

Like:

Container example = new Container();

example.setMap(new HashMap());
example.getMap().add(key, value);

session.save(example);


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 17, 2008 12:08 pm 
Newbie

Joined: Sat May 17, 2008 5:22 am
Posts: 8
Thanks for the help elvanor. It was very useful. Can i solve the same problem using HQL(Hibernate Query Language) . Can you help in writing the HQL query. Can you help in that ?


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 17, 2008 1:37 pm 
Beginner
Beginner

Joined: Wed Dec 20, 2006 11:21 am
Posts: 20
I am not sure you can use an HQL query to update this (although I am not experienced in HQL). I think HQL is only for querying (I may be wrong).


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.