-->
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.  [ 4 posts ] 
Author Message
 Post subject: Change hbm file dyanamically at runtime?
PostPosted: Mon Nov 10, 2008 6:45 am 
Newbie

Joined: Sat Oct 11, 2008 3:31 am
Posts: 11
Hi guyz,


Is there any way to change hbm file at runtime in hibernate .

If so please do post me the reply with demo code sample.

Thank you!!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 10, 2008 7:05 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
It depends on what you mean with "at runtime". Once the SessionFactory has been built, you can't make any configuration changes to it. You'll need to create a new SessionFactory from scratch. This can take quite a long time and is nothing that should be done at regular basis.

In our project, we are doing some "dynamic" changes at application startup. We have a "template" hbm.xml file which we read in as a XML Document and set the values for <class entity-name="..." table="..."> (and a few others). Those values are kept in a separate configuration file. When the application has started we don't change this so it is a one-time event only.


Top
 Profile  
 
 Post subject: Re: Change hbm file dyanamically at runtime?
PostPosted: Fri Oct 15, 2010 9:47 am 
Newbie

Joined: Tue May 18, 2010 5:39 am
Posts: 19
How do you exactly do this ?. Can you post an example please.

Basically I have a custom id generator and Iset pool size of ids as following :

<generator class="com.x.y.z.CutomIdGenerator">
<param name="segment_value">SomeValue</param>
<param name="optimizer">pooled</param>
<param name="increment_size">50</param>
</generator>

I want to change increment_size value from 50 to say 10 for some other deployment without disturbing the hbm files. This I want to do using property file which will be outside the jar file (jar file will have hbms and will be same for all customers)

_________________
AG
http://anshuiitk.blogspot.com


Top
 Profile  
 
 Post subject: Re: Change hbm file dyanamically at runtime?
PostPosted: Fri Oct 15, 2010 1:15 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Long time ago this one... I'll post a few links to our code:

First, the actual code that takes a Hibernate Configuration object and programmatically adds a new entity to it.
http://base.thep.lu.se/browser/tags/2.1 ... .java#L298

Then, the template file, which is more or less a regular hbm.xml file:
http://base.thep.lu.se/browser/tags/2.1 ... awData.xml


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