-->
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.  [ 3 posts ] 
Author Message
 Post subject: Programmatically reading mapping data
PostPosted: Wed May 04, 2005 9:26 am 
Newbie

Joined: Tue Mar 08, 2005 11:29 am
Posts: 14
Hello all,

I'm currently working on a part of a J2EE web-based application using Spring and Hibernate. Specifically, I'm trying to implement auditing within the application. To that end I need to pull the database name, schema name, and table name which should be contained within the mappings for the domain classes. I'm just unclear on how to get this information for read-only purposes.

I've done some searching here in the forums and lots of warm fuzzy time with the JavaDocs but I still don't see how to get that information. Anyone have any idea how to go about doing that?

Thanks,
C


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 10:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
By far the "easiest way" is to maintain a reference to the Configuration from which you generated the SessionFactory, which you can then use to call Configuration.getClassMapping(Class), which returns an instance of PersistentClass representing the mapping information defined for the requested class. PersistentClass has exposed methods to get all the information you are after.

If you don't have the Configuration available, it is still doable. Basically, you need to cast the session factory to type SessionFactoryImplementor and call it's getPersister(Class), which returns an instance of ClassPersister. Cast the ClassPersister to EntityPersister and call its getTableName() method. The result of getTableName() is the qualified table name.


Top
 Profile  
 
 Post subject: Thanks!
PostPosted: Wed May 04, 2005 11:09 am 
Newbie

Joined: Tue Mar 08, 2005 11:29 am
Posts: 14
Thanks for the point in the right direction, Steve! It's mucho appreciated.

C


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