-->
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: sql update and table names
PostPosted: Fri Dec 26, 2003 1:08 am 
Beginner
Beginner

Joined: Mon Sep 15, 2003 6:55 pm
Posts: 29
Is there a way, programatically, to find the table name for a given class? For example, what table is the com.mine.Bob class mapped to?

I am trying to do an sql update. I know that the table name is in the mapping file, but I would like to be able to change it in the future without having to remember to change this sql query.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 26, 2003 1:58 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You could get it from the Configuration Object i think by calling getClassMapping(<your class>).getTable().getName(). I dont think there is a way to get it from the SessionFactory or the Session


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 26, 2003 4:37 pm 
Beginner
Beginner

Joined: Mon Sep 15, 2003 6:55 pm
Posts: 29
Thanks! That works.

I can't find a way to get it from the SessionFactory or the Session either - you would think there would be a getConfiguration() method. This is what I ended up doing:
DatabaseHelper.getConfiguration().getClassMapping(LinkDAO.class).getTable().getName();


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 27, 2003 6:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You could to somethink like this, I think (relying on Hibernate internals):

Code:
SessionImpl impl = (SessionImpl) session;
Loadable loadable = (Loadable) impl.getClassPersister(<your class>);
String fromFragment = loadable.fromTableFragment("an_alias");

Be warned however, I have not tested this, don't know if this works and this may change anytime. Use on your own risk :)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 27, 2003 6:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
...and that code will return a string on the form "table1 an_alias_0, table2 an_alias_1, ..." if the class is mapped to multiple tables. (if i remember correctly)

_________________
Max
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.  [ 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.