-->
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.  [ 5 posts ] 
Author Message
 Post subject: Easy way to determine field length?
PostPosted: Fri Feb 04, 2005 8:52 pm 
Beginner
Beginner

Joined: Tue Nov 09, 2004 9:48 am
Posts: 23
I'd like my Swing GUI application to be able to query a Hibernate persisted object and get length information (if set in the hbm.xml) to use for validation. I can't find anything in the docs that indicates there's a way, but it seems a logical thing to provide.

Is there a way to do this that I'm overlooking?

Thanks for the help!

jbwiv


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 04, 2005 9:41 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Keep the Configuration object and query its meta data. The forum has some code examples here and there...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 04, 2005 11:58 pm 
Beginner
Beginner

Joined: Tue Nov 09, 2004 9:48 am
Posts: 23
I see how you can get table data with PersistentClass.getTable(), but is there any way to map column names to object attribute names? I can get column info just fine, and as long as I follow convention of naming my columns identically to my object's attributes, I'm ok. But that's not always the case in our schema.

Thanks very much for your help!.

jbwiv


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 05, 2005 5:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Try something alone the lines as this:
Code:
public int getColumnSize(Class mappedClass, String propertyName)
{
    Configuration cfg= HibernateUtils.getConfig();
    PersistentClass pClass= cfg.getClassMapping(mappedClass);
    Property hibProp= pClass.getProperty(propertyName)
    Iterator it= hibProp.getColumnIterator();
    while (it.hasNext()) {
        Column col= (Column) hibProp.getColumnIterator().next();
        return col.getLength();
    }
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 08, 2005 10:35 am 
Beginner
Beginner

Joined: Tue Nov 09, 2004 9:48 am
Posts: 23
David,

That did just the trick. Thanks!

jbwiv


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