-->
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.  [ 6 posts ] 
Author Message
 Post subject: Can I get resultset (table rows) in java.util.Map
PostPosted: Thu Mar 22, 2007 7:23 am 
Newbie

Joined: Thu Mar 22, 2007 6:43 am
Posts: 2
Mapping documents: N/A
Code between sessionFactory.openSession() and session.close(): N/A
Full stack trace of any exception that occurs: N/A
The generated SQL (show_sql=true): N/A
Debug level Hibernate log excerpt: N/A
Problems with Session and transaction handling? No

Hibernate version: 3.0
Database: Oracle 10g R2


Problem: Fetching table rows as Map object with column name as key and corresponding column value as value in the Map object.

# Assume i have following table with Schema:

T_USERS (
USER_ID varchar2(50),
FIRST_NAME varchar2(100)
LAST_NAME varchar2(100),
JOIN_DATE DATE,
JOB_LEVEL INTEGER
);

The table data being:
-------------------------------------------------------------------------
USER_ID | FIRST_NAME | LAST_NAME | JOIN_DATE | JOB_LEVEL
-------------------------------------------------------------------------
1 | John | Dow | 01/12/2006 | 12
2 | Sally | null | null | 8
------------------------------------------------------------------------

# In the hibernate configuration,
assume I mapped this table to java class called "User" and
it has a map variable/field called "userData" as follow:

class User {
private java.util.Map userData;
.....
}

# This will fetch 2 User objects for 2 rows in that table.

# But also what i want is - in each of those User objects i would like to
get "userData" map getting filled with key being "column name" and
value being the value in that table row.

e.g., For 1st row the userData map should contain:
- USER_ID to String "1"
- FIRST_NAME to String "John"
- LAST_NAME to String "Dow"
- JOIN_DATE to java.util.Date object with value "01/12/2006"
- JOB_LEVEL to java.lang.Interger object with value(12).

e.g., For 2nd row the userData map in 2nd User object should contain:
- USER_ID to String "2"
- FIRST_NAME to String "John"
- JOB_LEVEL to java.lang.Interger object with value(8).

So all the column names should be populated as keys in the map object
and corresponding column values populated as values in map object.
And if possible, populate the values as the appropriate well known java type object.

NOTE: Also note that i don't know the columns names before hand.
I don't want to hard-code the column names in .hbm.xml files..
So if tomorrow if i add a new column called "DEPARTMENT" to the underlying table, then i should automatically get the "DEPARTMENT" value in the Map object without having to update any of my .hbm.xml files....
So there shouldn't be any changes to hibernate configuration and reload of configuration for this.

Can we do this thru hibernate f/w ???

Appreciate any help on this as it is very much required for our project .
Let me know any sort of way either extending hibernate or configuration etc. for this.

Thx much.


Last edited by dsssatya on Thu Mar 22, 2007 8:07 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Change the session mode
PostPosted: Thu Mar 22, 2007 7:52 am 
Newbie

Joined: Mon Nov 21, 2005 6:15 am
Posts: 14
You can change the session mode. By default the query mode is POJO. Options are POJO, MAP and XML.

For examples on how to do this, check,
file:///C:/Installs/Java/hibernate-3.0.5/doc/reference/en/html_single/index.html#persistent-classes-dynamicmodels


Top
 Profile  
 
 Post subject: Change the session mode
PostPosted: Thu Mar 22, 2007 7:54 am 
Newbie

Joined: Mon Nov 21, 2005 6:15 am
Posts: 14
You can change the session mode. By default the query mode is POJO. Options are POJO, MAP and XML.

For examples on how to do this, check,
http://www.hibernate.org/hib_docs/v3/re ... amicmodels


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 8:35 am 
Newbie

Joined: Thu Mar 22, 2007 6:43 am
Posts: 2
Thx much for reply.

The approach indicated by you totally assumes everything will be in dynamic-map mode (every java object viewed by hibernate will be in tems of hierarchical map objects)... But i don't want that.

Basically i still want to set the default_entity_mode to pojo. But only for this particular object User (for T_USER table) - i want to get the row data in Map object.

Also note that i don't know the columns names before hand. I don't want to hard-code the column names in .hbm.xml files..
So if tomorrow if i add a new column called "DEPARTMENT" to the underlying table, then i should automatically get the "DEPARTMENT" value in the Map object without having to update any of my .hbm.xml files.... So there shouldn't be any changes to hibernate configuration and reload of configuration for this.

Is there any way to achieve that?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 27, 2007 2:13 am 
Newbie

Joined: Sat Mar 24, 2007 8:14 am
Posts: 15
i have the same problem , can nebody help us out ?

Thjanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 2:30 am 
Newbie

Joined: Sat Mar 24, 2007 8:14 am
Posts: 15
yes, you can get the column name but for that u have to implement getReturnedAlias method of the Qeury .

or refer to this link, i think it will give u better idea.

please refer to this linik:
http://forums.hibernate.org/viewtopic.p ... 695af03b11

Regards


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