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: Mapped Table column information
PostPosted: Mon Aug 25, 2008 9:06 am 
Newbie

Joined: Mon Aug 25, 2008 8:39 am
Posts: 10
I am trying to get table column names corresponding to persistent object class properties from a hibernate interceptor class.

I have looked at ClassMetaData which provides property Name information but does not provide table schema information. Also looked at org.hibernate.mapping.PersistentClass javadocs, but it is not clear how to get the column names.

Thanks


Top
 Profile  
 
 Post subject: Re: Mapped Table column information
PostPosted: Thu Dec 04, 2008 4:27 pm 
Newbie

Joined: Wed Nov 08, 2006 2:30 pm
Posts: 6
vjhiber wrote:
I am trying to get table column names corresponding to persistent object class properties from a hibernate interceptor class.

I have looked at ClassMetaData which provides property Name information but does not provide table schema information. Also looked at org.hibernate.mapping.PersistentClass javadocs, but it is not clear how to get the column names.

Thanks


I am quite late, but in case you haven't found it yet or somebody else is looking for the solution:

Code:
Iterator<Property> props = factoryBean.getConfiguration().getClassMapping(entityClass.getName()).getPropertyClosureIterator();
while (props.hasNext()) {
    Iterator<Column> cols = p.getColumnIterator();
    while (cols.hasNext()) {
         Column c = cols.next();
         logger.debug(i + ". column Name: " + c.getName());
         logger.trace(i + ". column Nullability: " + c.isNullable());
         logger.trace(i + ". column Length: " + c.getLength());
         logger.trace(i + ". column Precision: " + c.getPrecision());
         }
}
            


entityClass should be the class you are looking for and replace the FactoryBean with whatever object created your Session. The object should provide you with access to the Configuration.

Don't rely on the column information, though. At least the length is not correct for me using Postgres and Hibernate 3.2.5


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.