-->
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.  [ 2 posts ] 
Author Message
 Post subject: How can i get a full column name in Hibernate
PostPosted: Sun Sep 20, 2009 11:43 pm 
Newbie

Joined: Sat Sep 19, 2009 1:28 am
Posts: 3
Hi,
I am implementing Hibernate UserType.
I tried to access the full column name from ResultSetMetaData provided in nullSafeGet method,
below is the code snappet


public Object nullSafeGet( ResultSet resultSet, String[] names, Object owner ) throws HibernateException,
SQLException {
ResultSetMetaData metaData = resultSet.getMetaData();
int numberOfColumns = metaData.getColumnCount();
// get the column names; column indexes start from 1
for (int i = 1; i < numberOfColumns + 1; i++) {
if( names[0].equalsIgnoreCase( metaData.getColumnName( i ) ) ) {
String columnName = metaData.getColumnName(i);
System.out.println( "column name=" + columnName );
}



}

return object;
}



but here i m getting alias names of that columns,
but if i run the same program using JDBC without hibernate, i m getting exact column names.
One more thing i am getting "owner" object as null, can you tell me why i am getting this as null.
So, can you help me out on this issue ASAP


Top
 Profile  
 
 Post subject: Re: How can i get a full column name in Hibernate
PostPosted: Mon Sep 21, 2009 7:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
satya_aeks wrote:
but here i m getting alias names of that columns,


yes, that is expected since that is the names you need to refer to for getting the data out of the result set!

Quote:
but if i run the same program using JDBC without hibernate, i m getting exact column names.


nope - you are just using the same name for your alias as the columns.

We use aliases to ensure you can actually join tables with same column names.

What is it you need the column name for ?

_________________
Max
Don't forget to rate


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