-->
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: Can Hibernate register an entity class at runtime
PostPosted: Fri Jul 15, 2016 8:17 pm 
Newbie

Joined: Fri Jul 15, 2016 8:09 pm
Posts: 2
Can hibernate register an entity class dynamiclly without recreating the session factory in runtime?


Top
 Profile  
 
 Post subject: Re: Can hibernate registry an entity class in runtime
PostPosted: Mon Jul 18, 2016 3:52 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
No. The bootstrap process creates the Metadata and passes it to the SessionFactory upon instantiation. For this reason, you can not add entities dynamically to a SessionFactory, meaning that you need to recreate it from scratch.

However, the SessionFactory initialization can be done programmatically so you can recreate it whenever you have new entities that need to be registered.


Top
 Profile  
 
 Post subject: Re: Can hibernate registry an entity class in runtime
PostPosted: Thu Jul 21, 2016 9:35 pm 
Newbie

Joined: Fri Jul 15, 2016 8:09 pm
Posts: 2
mihalcea_vlad wrote:
No. The bootstrap process creates the Metadata and passes it to the SessionFactory upon instantiation. For this reason, you can not add entities dynamically to a SessionFactory, meaning that you need to recreate it from scratch.

However, the SessionFactory initialization can be done programmatically so you can recreate it whenever you have new entities that need to be registered.


Firstly, thank you very much for your gentle response.
One more question, After creating a new SessionFactory, shall I close the old one? If I do, will all the sessions and transactions related to it throw exceptions at this time? How can I get a smooth transition while trying to rebuild a SessionFactory?


Top
 Profile  
 
 Post subject: Re: Can hibernate registry an entity class in runtime
PostPosted: Fri Jul 22, 2016 9:12 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You should close the old SessionFactory because and deallocate all its resources (e.g. connection pool, caches, metadata). Related to that transition, you could probably orchestrate it in your application code. Hibernate does not offer anything for this particular use case.


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.