-->
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 to get class name from Table name?
PostPosted: Thu Nov 10, 2005 11:13 pm 
Newbie

Joined: Thu Nov 10, 2005 11:05 pm
Posts: 4
Hi,
I am a newbie to Hibernate, and after I successfully setup a simple hibernate environment in one of my project, I've encoutered a problem: given a table's name, how could I get its corresponding class name through Hibernate's API? I don't want map file analyzing or NamingStrategy-based guessing, is there another more graceful solution?
Thanks a lot![/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 11, 2005 2:03 am 
Beginner
Beginner

Joined: Tue Oct 18, 2005 3:57 pm
Posts: 48
Location: Los Angeles, CA
Try using Configuration.getClassMappings():

Code:
Configuration cfg = ...
String tableName = ...
String className = null;

for (Iterator iter = cfg.getClassMappings(); iter.hasNext(); ) {
   PersistentClass pc = (PersistentClass) iter.next();
   if (tableName.equalsIgnoreCase(pc.getTable().getName())) {
      className = pc.getClassName();
   }
}


jd

--------------------------
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.