-->
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: Getting the table name and column name using the class name
PostPosted: Mon Apr 17, 2006 9:17 am 
Newbie

Joined: Thu Jun 17, 2004 10:15 am
Posts: 3
Location: US
Hi,

I would like to know how to retrieve the table name and column name for a particular class if I know the class name and the property name corresponding to the column name.

Regards

Uday

_________________
Uday


Top
 Profile  
 
 Post subject: Re: Getting the table name and column name using the class n
PostPosted: Tue Apr 18, 2006 3:40 am 
Newbie

Joined: Sat Nov 22, 2003 9:21 pm
Posts: 18
Location: Malaysia
Hi,

Use ClassMetaData API.
http://www.hibernate.org/hib_docs/v3/ap ... adata.html

For example,
Code:
ClassMetaData persistMetaData = sessionFactory.getClassMetaData( PersistentClass.class );
System.out.println( "Entity table [" + persistMetaData.getEntityName() + "]" );


Regards,
Edward


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 11:29 am 
Senior
Senior

Joined: Wed Aug 17, 2005 12:56 pm
Posts: 136
Location: Erie, PA (USA)
The only way I can see to do it is to start from the Configuration and then step into the related collections. Note that not all properties have a column, i.e. one-to-one.
Code:
for (Iterator it1 = config.getClassMappings(); it1.hasNext(); ) {
  PersistentClass pc = (PersistentClass)it1.next();
  System.out.println("Table is " + pc.getTable().getName());
  for (Iterator it2 = pc.getPropertyIterator(); it2.hasNext(); ) {
    Property property = (Property)it2.next();
    System.out.println("Property is " + property.getName());
    for (Iterator it3 = property.getColumnIterator(); it3.hasNext(); ) {
      Column column = (Column)it3.next();
      System.out.println("Column is " + column.getName());
    }
  }
}

Good luck,
Curtis ...

_________________
---- Don't forget to rate! ----


Last edited by CWitherow on Wed Jun 14, 2006 8:43 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: How to get table name and column name
PostPosted: Tue Jun 13, 2006 5:48 pm 
Newbie

Joined: Thu Jun 17, 2004 10:15 am
Posts: 3
Location: US
Hi CWitherow,

I am using spring LocalSessionFactorybean which can give me the Hibernate configuration object. But I am not able to get this object from application Context. It throws ClassCastException when I try to get this from applicationContext. Is there is any other way of getting access to the Configuration in the Hibernate Interceptor object.

Regards

Uday

_________________
Uday


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.