-->
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.  [ 9 posts ] 
Author Message
 Post subject: Help with table mapping
PostPosted: Fri Jul 14, 2006 1:40 pm 
Newbie

Joined: Fri Jul 14, 2006 12:19 pm
Posts: 6
Hi,

I am evaluating hibernate to replace an existing ORM technology that we have working on for quite some time now. This ORM is a part of a framework which is used by an enormous application (About 8000 tables, data sizes upwards of 2 - 3 TB). We use a combination of restrictive discipline ( forcing the developers to have no interaction with the database, and generating the table schema and the queries by inspecting the class ) and object orientation (to abstract some functionality) to achieve ORM.

Now to plug in Hibernate without significant update (read damage) to the framework, I need to find a way to achieve 2 tasks :

1. Ability to avoid an extra deployment artifact, the *.hbm.xml (considering about 8000 data classes, there would be 8000 extra artifacts to manage. And since these classes are created by different developers, I cant have it in a single file. mapping JAR seems to be an option, but still it does not eliminate 8000 extra elements in my CVS ). Is there a way to generate mappings programmatically and add it to the configuration??

2. Considering that the application database has 8000 tables,not all of it is used frequently, infact, quite a few are for monthly or yearly processing. So is it wise to load up the mappings for all these tables in advance?? Also I would not prefer doing it in the hibernate.cfg.xml file as adding 8000 odd entries in a single file can be error prone. Can i split the mapping information into multiple config files, so that I can use different mapping.cfg for different functional modules of the application? What is the memory/performance implication of adding 8000 mapping objects at startup?

PS: I have consulted quite a few articles and documentation before posting this, however if I have missed a document that explains this, please bear with me and point me in the right direction.

vipin


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 14, 2006 2:12 pm 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
You could use annotations instead of mapping files.

Also you can use Configuration class to programmatically create a SessionFactory with a different set of mappings.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 15, 2006 5:55 am 
Newbie

Joined: Fri Jul 14, 2006 12:19 pm
Posts: 6
Sorry if i missed this information before, but im using JDK 1.4... with no near plans for a jdk 1.5 upgrade. And I am aware that configuration can be set programmatically. But could i set mappings programmatically, ie instead of using the addClass() or addFile() API calls, could i just create my own instance of a Mappings class and add it to the configuration? I would want to do this so that I can inspect the metadata of my own classes and have a small runtime code that would generate the mappings appropriately.

Now if I could do it, It brings me to my next concern. Since adding a mapping requires sessionFactory to be created again, Is there a way to plug in a mapping into a hibernate session so that I could load up the mapping for a class on demand? The documents I have gone through suggests that this cannot be done. Hence the next question, what is the overhead of loading up 8000 mapping objects at startup?

Please let me know if you need more information


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 15, 2006 5:55 am 
Newbie

Joined: Fri Jul 14, 2006 12:19 pm
Posts: 6
(Sorry for the accidental repost. There was some php emailer error, and without checking, I resubmitted the information, and im unable to delete this post. Any Admins watching, who could delete this for me??)

Sorry if i missed this information before, but im using JDK 1.4... with no near plans for a jdk 1.5 upgrade. And I am aware that configuration can be set programmatically. But could i set mappings programmatically, ie instead of using the addClass() or addFile() API calls, could i just create my own instance of a Mappings class and add it to the configuration? I would want to do this so that I can inspect the metadata of my own classes and have a small runtime code that would generate the mappings appropriately.

Now if I could do it, It brings me to my next concern. Since adding a mapping requires sessionFactory to be created again, Is there a way to plug in a mapping into a hibernate session so that I could load up the mapping for a class on demand? The documents I have gone through suggests that this cannot be done. Hence the next question, what is the overhead of loading up 8000 mapping objects at startup?

Please let me know if you need more information


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 15, 2006 6:52 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
vipinr wrote:
could i just create my own instance of a Mappings class and add it to the configuration?

Yes.

building your own XML:
Code:
public Configuration addInputStream(InputStream xmlInputStream);
public Configuration addXML(String xml);


programatically:
Code:
public Mappings createMappings();


vipinr wrote:
Is there a way to plug in a mapping into a hibernate session?

No.
But you could have the 'normal' Configuration that creates the 'normal' SessionFactory that .....
And in some special moments (monthly and yearly) create a 'special' Configuration that creates a 'special' .... and when finished destroy them.
This would also help to factorize your app.


Last edited by pepelnm on Sat Jul 15, 2006 6:58 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 15, 2006 6:57 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
Do you know XDoclet and their hibernatedoclet tag?

hibernatedoclet


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 15, 2006 10:07 am 
Newbie

Joined: Fri Jul 14, 2006 12:19 pm
Posts: 6
Thanks for your replies pepelnm, but I am not very keen on reloading the configuration or restarting the application for running special configurations. my question on adding entries programmatically is more or less related to lazy loading of table mappings. So it would be helpful if your could confirm the performance impact of loading a huge number of table mappings at startup, since I cant alter the configurations after that? Or does Hibernate take care of not loading up all the mappings unless required??

And I have evaluated hibernatedoclet and its parent Xdoclet. Its quite a heavy tool for such simple purposes, not to mention adding another set to dependencies to a product. I would rather write my own XML generators ( no offence ) .

Again from the replies I am guessing that I cannot have table mappings spread across multiple cfg files, unless I myself aggregate it and add it to configuration programmatically.

As I am away from my office I cant check, but I hope the configuration object is serializable, so that I could persist it and save previous time during unplanned downtimes.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 15, 2006 3:35 pm 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
vipinr wrote:
restarting the application for running special configurations

No-one has talked of reload configuration or restart the app. It's not needed.
You can have more than one SessionFactory:
Code:
SessionFactory sf = new Configuration().configure().buildSessionFactory();
SessionFactory monthlySf = new Configuration().configure("monthly.cfg.xml").buildSessionFactory();
SessionFactory yearlySf = new Configuration().configure("yearly.cfg.xml").buildSessionFactory();


vipinr wrote:
lazy loading of table mappings

Impossible.

vipinr wrote:
does Hibernate take care of not loading up all the mappings unless required?

No. It loads and process every map file when you configure a Configuration object or when you build a SessionFactory, I don't remember.

Both Configuration and SessionFactory implement Serializable.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 16, 2006 5:41 am 
Newbie

Joined: Fri Jul 14, 2006 12:19 pm
Posts: 6
Thanks for your help in finding the answers.

Unfortunately I have to worry more of such dynamic behavior as I am responsible for a framework that other developers use to build useful applications. I dont even know the functionality of a couple of products built on this famework. And at the framework level, I have no clue what tables would be used by a developer and in what context, so preloading the table mappings is surely gonna impact the decision to integrate hibernate, unless ofcourse I miraculously find a way to overrride the default behavior of the core classes :).


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