-->
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.  [ 7 posts ] 
Author Message
 Post subject: Possible to obtain a map from database directly?
PostPosted: Wed Dec 14, 2005 10:59 pm 
Newbie

Joined: Wed Dec 14, 2005 10:47 pm
Posts: 11
Hi!

I have a table with only 2 columns, 'KEY' and 'VALUE'. I would like to retrieve a Map object from Hibernate with the key mapped to 'KEY' and value mapped to 'VALUE' instead of having to create a POJO to represent each record and returning as a list, after which I have to manually retrieve each record and store the key and value to a Map object. I'm using Hibernate with Spring, running on Oracle 10g, so I'm using Spring's HibernateTemplate object to perform my database operations. Anybody knows if it is possible in Hibernate to obtain a Map object directly without having the need to create POJO and mapping to the table?

Adrian


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 11:01 pm 
Regular
Regular

Joined: Mon Aug 22, 2005 1:11 pm
Posts: 50
Location: Pasadena, CA
if you are using Spring you can just use the JdbcTemplate to access your database directly with SQL statements and not use hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 11:05 pm 
Newbie

Joined: Wed Dec 14, 2005 10:47 pm
Posts: 11
Ok... But is it possible if I want to use Hibernate to do this? Architecture-wise, this can be messy since both Spring and Hibernate are used to access the database.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 11:08 pm 
Regular
Regular

Joined: Mon Aug 22, 2005 1:11 pm
Posts: 50
Location: Pasadena, CA
Well Hibernate is not really meant to be used that way you have to have the object struct there for it do anything, since it works on object relations not database relations.

As far as the architure goes this should be a problem as long you are not trying to change persistant object directly. If you just using jdbc to query it should be fine. Do it all the time :).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 11:21 pm 
Newbie

Joined: Wed Dec 14, 2005 10:47 pm
Posts: 11
I see.... Hmm... Now I'll have to figure how to declare and obtain the jdbcTemplate. :P Thanks for the info!

Adrian


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 11:25 pm 
Regular
Regular

Joined: Mon Aug 22, 2005 1:11 pm
Posts: 50
Location: Pasadena, CA
Well you just have you class that is accessing the data ( your DAO object) extend JdbcDaoSupport and either set or inject your datasource.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 11:43 pm 
Newbie

Joined: Wed Dec 14, 2005 10:47 pm
Posts: 11
Alrighty then... Thanks!


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