-->
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 delete a mapping class from Configuration
PostPosted: Tue Nov 07, 2006 5:49 am 
Newbie

Joined: Tue Jan 17, 2006 9:48 pm
Posts: 16
I want runtime change a mapping class. I have read lots of topics, rebuild SessionFactory is a reasonable way. However, it is too long to rebuild all mapping classes.
My idea is just replace the changed class (Only one or two). There are lots of add mapping class methods in Configuration, but how to delete one existed class?
I found all add mapping classes finally go to HbmBinder.bindRoot(). This method do many binds. I don't know how to remove these binds when delete class.


Top
 Profile  
 
 Post subject: My solution
PostPosted: Fri Nov 10, 2006 4:27 am 
Newbie

Joined: Tue Jan 17, 2006 9:48 pm
Posts: 16
No one answer me. I find a solution myself:
Hibernate Configuration object does not provide API for remove mappings. We need write a new Configureation extends from Hibernate Configuration, in order to add remove mapping method.
Please refer to the HibernateConfiguration class in our POC project for detail. Here are remove mapping method:
Code:
public void removeMapping(String path) throws MappingException  {
      log.info( "Remove mappings from resource: " + path );      
      PersistentClass cls = this.getClassMapping(path);
      Table tbl = cls.getRootTable();   
      try {
         super.classes.remove(path); //Remove mapped class
         super.tables.remove(tbl.getName()); //Remove mapped table
         super.imports.remove(path); //Remove mapping from import entry.
         super.imports.remove(cls.getNodeName()); //Remove mapping from import entry.
      }catch (MappingException me) {
         throw new MappingException( "Could not remove mappings from resource: " + path, me );
      }
   }

Please notes that there are 2 import entries for each mapping, one’s key is the mapping’s full class name, such as “com.report.PO”, the other is class name, such as “PO”.
This method can work well to simple mappings. But if you want support following mappings, please investigate the method and add more process:
(1) One mapping related to multiple tables.
(2) The mapping include collections.
(3) The mapping include sub classes.


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.