-->
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.  [ 5 posts ] 
Author Message
 Post subject: Dynamically creating tables
PostPosted: Tue Nov 25, 2003 7:51 pm 
Newbie

Joined: Sat Nov 22, 2003 8:42 pm
Posts: 9
Hello! My problem has been posted before by someone else but no one replied, please help!!!:

Previously posted message:
[i]"I have an application where an administrative user can create custom-defined entities in the database. Creating an entity involves defining the columns for the entity and storing the definition in the database. A table is created based on the definition to persist instances of the entity. Entities always have an id column as a primary key and a date column to indicate when the data was saved.

Is there a way to dynamically map Hibernate to these custom-defined entities, since they do not exist at deployment? I have searched high and low through the documentation, forum, and FAQs with no luck. I have found documentation that mentions using Dynabeans along with references to runtime mapping, but it is not clear from how this might be implemented.

Does anyone have insight as to if this can be done and how? If they can't be dynamically mapped, what is the appropriate way to take advantage of Hibernate's capabilities in this scenario? Examples would be greatly appreciated.

Thanks!"[/i]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 8:11 pm 
Beginner
Beginner

Joined: Fri Oct 10, 2003 4:54 pm
Posts: 26
Location: Chicago, IL
I'm not really sure that Hibernate is a good fit for your application. You would probably be better off rolling your own metadata based model for this situation (basically define a Table class, a Row class, etc, and populate them from the dynamic metadata).

That being said, if you really want to use Hibernate, your first problem would be that you will need to somehow dynamically generate the Java class that you want to map to. CGLIB might be a possiblity for doing that.

Once you have a Java class, you could dynamically generate an XML mapping file and configuration file to hold that mapping.

Next, you would just need to use the Configuration class to load your generated XML configuration and create a SessionFactory. From there you are cranking away with Hibernate.

This is about the simplest approach I can think of, although you would probably end up wanting to enhance it (for example, you might want to have your generated configuration file hold all of your dynamically generated mapping files so that you could access all of them from the same Hibernate Session object, and you might want to have some level of indirection between your code and the SessionFactory so that you can "hotswap" the SessionFactory being used.)

Hopefully this helps.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 30, 2003 4:11 pm 
Beginner
Beginner

Joined: Fri Aug 29, 2003 3:39 pm
Posts: 33
Location: San Francisco, CA
loverde wrote:
That being said, if you really want to use Hibernate, your first problem would be that you will need to somehow dynamically generate the Java class that you want to map to. CGLIB might be a possiblity for doing that.


In CVS CGLIB has a BeanGenerator class that can be used to generate JavaBeans at runtime. It might be useful for this scenario.

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 30, 2003 8:55 pm 
Regular
Regular

Joined: Fri Sep 05, 2003 12:01 am
Posts: 80
Location: Bogot
sounds like you need an entity enigine.


check out the Ofbiz entity engine. It lets you create entities (which map to db tables) at runtime.

http://www.ofbiz.org

Im not really sure hibernate is a fit for this, but anyone who knows better feel free to correct me.[/url]

_________________
Mauricio Hern


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 21, 2005 6:48 pm 
Newbie

Joined: Tue Jan 18, 2005 10:41 pm
Posts: 15
Hi Andres,

I have a very similar situation. Extra columns can be added to a table by the administrator whenever required. A number of “meta data” tables are used to define the function of the table. Sounds familiar?

How did you solve your problem?

Richard


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