-->
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.  [ 6 posts ] 
Author Message
 Post subject: Getting table name for persistent class
PostPosted: Fri Oct 24, 2003 10:21 am 
Newbie

Joined: Fri Oct 24, 2003 10:07 am
Posts: 3
Hi,

Is there anyway to get the associated table name for a given persistent class? A part of my application requires a mass update where I need to make my own sql calls and I would like to abstract this to a number of similiar entities.

thanks,

josh


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 3:48 pm 
Regular
Regular

Joined: Tue Sep 16, 2003 11:35 am
Posts: 93
Location: San Francisco, CA
I found the following object navigation:

net.sf.hibernate.cfg.Configuration
net.sf.hibernate.cfg.Mappings
net.sf.hibernate.mapping.PersistentClass
net.sf.hibernate.mapping.Table


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 4:57 pm 
Newbie

Joined: Fri Oct 24, 2003 10:07 am
Posts: 3
thanks, I also found the following works:

Code:
SessionFactory sf = ...
SessionFactoryImplementor sfi = (SessionFactoryImplementor) sf;
EntityPersister ep =(EntityPersister) sfi.getPersister(entity.getClass());
String tablename = ep.getTableName();


this way I don't have to hold a reference to the configuration object...
However, it makes me a little nervous. Any reason I shouldn't do this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 4:58 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
type casts from API classes to internal implementation classes should always make you nervous.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 6:16 pm 
Newbie

Joined: Fri Oct 24, 2003 10:07 am
Posts: 3
Good point. It also makes me a little nervous holding on to the Configuration since it says in the documentation:

Quote:
A Configuration is intended as a configuration-time object, to be discarded once a SessionFactory is built.


I would suggest adding table name to the meta data api, but I have a suspicion this would open up a can 'o worms that is very purposely sealed tight.

a little background on my problem:

I am refactoring a bunch of application code to use hibernate. some of the database tables use the [url]Modified Preorder Tree Traversal Algorithm[/url] which is a way of ordering hierarchical data that is optimized for lots of reading and not so much writing. What makes it not so good for writing is that you need to do a batch update everytime you add something arbitarily to some point in the tree. Anyway, got it working well with one entity (using some batch update sql code) but would like to resuse this code for other entities...

And the reason I am rambling on is... I am wondering if there is some way to encapsulate this behavior at some lower level in hibernate that is not documented but is perfectly acceptable api usage. Otherwise, maybe I should just bite the bullet and cut-and-paste...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 25, 2003 6:44 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
jrl wrote:
Good point. It also makes me a little nervous holding on to the Configuration since it says in the documentation:

Quote:
A Configuration is intended as a configuration-time object, to be discarded once a SessionFactory is built.




It is just a statement of intention - not a "You are not allowed to keep configuration around"-disclaimer ;)

There are no problems in keeping a Configuration around if you want to - you could also just extract the information you need and keep it some for you application better structure....

jrl wrote:
I would suggest adding table name to the meta data api, but I have a suspicion this would open up a can 'o worms that is very purposely sealed tight.


Yes - we are not very keen on unwinding to much of the SessionFactory metadata API....you should view the SessionFactory metadata as a compiled and "denormalized" version of the metadata available via Configuration..

So, if you can manage your problem with SF metadata then use that - if not, then use the metadata available in Configuration.

jrl wrote:
I am refactoring a bunch of application code to use hibernate. some of the database tables use the [url]Modified Preorder Tree Traversal Algorithm[/url] which is a way of ordering hierarchical data that is optimized for lots of reading and not so much writing. What makes it not so good for writing is that you need to do a batch update everytime you add something arbitarily to some point in the tree. Anyway, got it working well with one entity (using some batch update sql code) but would like to resuse this code for other entities...

And the reason I am rambling on is... I am wondering if there is some way to encapsulate this behavior at some lower level in hibernate that is not documented but is perfectly acceptable api usage. Otherwise, maybe I should just bite the bullet and cut-and-paste...


hmm - if you could show us what the code you don't like cut-and-pasting are doing then I think we can answer that waay better ;)

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