-->
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: Return column name
PostPosted: Fri Jun 09, 2006 6:37 pm 
Newbie

Joined: Fri Jun 09, 2006 6:34 pm
Posts: 5
Hello, to all?!?How can I return the column names?Does anybody know?!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 09, 2006 6:57 pm 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
Interface QueryTranslator

public String[][] getColumnNames()


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 10, 2006 6:43 pm 
Newbie

Joined: Fri Jun 09, 2006 6:34 pm
Posts: 5
Hi!!Thanks for the answer!!I'm trying this:
Code:
   QueryTranslator qt = (QueryTranslator) HibernateUtility.getSession().createCriteria(Aluno.class);
      String[][] string = qt.getColumnNames();
      for(int i=0; i<=string.length; i++){
         for(int j=0; j<=string.length; j++){
            System.out.println(string[i][j]);
         }
      }

But nothing happens!!What's wrong?!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 10, 2006 7:05 pm 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
QueryTranslator is for HQL.

I think that you need:

Interface CriteriaQuery


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 10, 2006 8:54 pm 
Newbie

Joined: Fri Jun 09, 2006 6:34 pm
Posts: 5
Nothing happened!!!Could you give an example?!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 11, 2006 1:32 pm 
Senior
Senior

Joined: Tue Mar 09, 2004 2:38 pm
Posts: 141
Location: Lowell, MA USA
If you're looking to get at the column names that would be returned by a mapped class, you can do something like this:

Code:
Configuration cfg = HibernateUtil.getConfiguration();
PersistentClass pc = cfg.getPersistentClass(Aluno.class.getName());
Iterator properties = pc.getPropertyIterator();
while(properties.hasNext()) {
   Property property = (Property) properties.next();
   Iterator columns = property.getColumnIterator();
   while(columns.hasNext()) {
      Column column = (Column) columns.next();
      System.out.println(column):
   }
}


If you're looking for the column names that are returned by a query, that gets a bit more complicated. The CriteriaQuery interface wasn't designed to be used by application code and doesn't offer an easy means of getting the data that you might be looking for.

Ryan-

_________________
Ryan J. McDonough
http://damnhandy.com

Please remember to rate!


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.