-->
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: Help trying to create tables on the fly
PostPosted: Tue Jan 06, 2009 9:11 am 
Newbie

Joined: Tue Oct 14, 2008 9:18 am
Posts: 1
I am working on a project for a client that indexes large files. One of the goals of the rewrite was to also do it in a way that any database could easily be used with it. So it was decided that hibernate would be used.

We got it all working with hibernate using hbm.xml mapping. But just recently two new requirement have been added. Firstly they want to be able to specify the type of an index (ie string, int etc) currently it only supports strings. Secondly they want it to make the structure more normalized, as currently a query string to do a search is very complex.

There have been two thoughts on how to do this. 1. A table for each of the data types. 2. Give the admin user the ability to create new tables on the fly (ie we currently have a table that takes 10 strings and 2 ints. The new file to be indexed takes 11 strings and 2 ints so make a new table).
The proposed process for this would be:

Startup looking like this:
1. Init Hibernate as we do now.
2. Check DB to see what tables have been created dynamically in the past.
3. Add the HBM.XML files for those tables to the configuration; maybe generated on the fly or stored in DB.
4. Re-create the session's factory with the updated configuration. All tables should be accessible.

Creating a new table:
1. Init Hiberanate configuration with no mappings.
2. Add the single mapping for the new table.
3. Run SchemaExport to create the table.
4. Re-init session's factory as above with the newest addition. The new table should be accessible.

I am thinking number 2 does not sound like a very good solution.

Could an experienced member please provide feedback.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2009 9:48 am 
Regular
Regular

Joined: Wed Oct 15, 2008 6:59 am
Posts: 103
Location: Chennai
you can Map the table/class in a *.hbm.xml.
Add this to you hibernate.cfg.xml

and set

<hibernate-configuration>

<session-factory>

<property name="hibernate.hbm2ddl.auto">create</property>


Hibernate then will create all tables which are referenced in you mapping.

_________________
If u feel it will help you, don't forget to rate me....


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.