-->
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.  [ 8 posts ] 
Author Message
 Post subject: How to add mapping files to SessionFactory after created?
PostPosted: Mon Nov 20, 2006 5:09 am 
Newbie

Joined: Mon Nov 20, 2006 4:58 am
Posts: 3
In my project ,we want to empower users to create their own object from our application UI, I know we can use hibernate tools to generate java files, mapping files and even the table in database.

My question is how can I dynamic add these mapping files to SessionFactory after it has been created in runtime without recreated the SessionFactory?


Top
 Profile  
 
 Post subject: Same Problem
PostPosted: Wed Nov 29, 2006 9:01 am 
Newbie

Joined: Wed Nov 29, 2006 8:45 am
Posts: 2
I have the same question.. does anyone knows how to solve it?

Any help will be appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 29, 2006 11:35 am 
Pro
Pro

Joined: Mon Jan 24, 2005 5:39 am
Posts: 216
Location: Germany
I think it is not possible,
because of the complex relations of objects already loaded in
a session.

_________________
dont forget to rate !


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 29, 2006 6:25 pm 
Senior
Senior

Joined: Sat Nov 27, 2004 4:13 am
Posts: 137
well, I think you must recreate the sessionfactory, but you can use session factory's mapping metadata...

_________________
don't forget to credit!

Amir Pashazadeh
Payeshgaran MT
پايشگران مديريت طرح
http://www.payeshgaran.co
http://www.payeshgaran.org
http://www.payeshgaran.net


Top
 Profile  
 
 Post subject: I have solved it
PostPosted: Wed Nov 29, 2006 9:15 pm 
Newbie

Joined: Mon Nov 20, 2006 4:58 am
Posts: 3
Create a new class same as Configuration.mapping;
Create a new SessionFactoryImpl just like the given one,change the visibility of identifierGenerators,entityPersisters and classMetadata to public ,then make classMetadata modifiable by remove the unmodifiable wrapper (classMetadata = Collections.unmodifiableMap(classMeta);)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 7:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
NO!

messing with the state of the sessionfactory is in no way supported or supposed to work!

Your suggested changes is not thread safe plus a dozen other side effects that can be caused by messing with thought to be immutable datastructures.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 9:22 pm 
Newbie

Joined: Mon Nov 20, 2006 4:58 am
Posts: 3
Thanks a lot for max's comment.

But is that means the only way that can add mappings to sessionFactory at run time is to recreate the sessionFactory at run time?

My question is if I do by that way ,how about the sessions created by the original sessionFactory?

Or maybe i shouldn't use hibernate in this case?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 31, 2007 2:21 pm 
Newbie

Joined: Wed Nov 29, 2006 8:45 am
Posts: 2
Yes, maybe the better option should be don´t use hibernate if you need to add mappings at runtime.

Thanks to krein reply, I started diving in hibernate source code, and actually I can restart sessionFactory hardcore-using new SessionFactoryImpl() constructor (and also changing some attribute access to public).

First of all, I get sure that are no clients using my server.

It works, but it´s very, very slow, and really a dirty solution. But better than restart the entire developement process of my application.


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